PDA

View Full Version : Extjs Grid date column issue



awirdev
22 Sep 2011, 6:03 AM
Hello everyone, i have ran into a little issue with the data grid, and could use your help:

I have a json data source that returns the date field as
"opened":"\/Date(1207022400000-0400)\/" . I have labeled the model field created as
{ name: 'opened', type: 'date' }, . In the grid, it's column is set up as
{ text: "Date Closed", dataIndex: 'opened', xtype:'datecolumn', type: 'date', dateFormat: 'm/d/Y' },

The issue is it's not rendering the date. I have been unable to find any examples out there showing how to handle this. Your help is greatly appreciated

Thanks!

twaindev
24 Sep 2011, 2:59 PM
Try this:


{ name: 'opened', type: 'date', dateFormat: 'MS' },

MS is a special format for Microsoft AJAX serialized dates.

See Ext.Date (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date).

HTH

Crockford
26 Sep 2011, 7:20 AM
Probably you are using a Microsoft Web service.

The only solution I found these months is this:

{ name: 'opened', type: 'date', convert: function (v, record) { return new Date(parseInt(v.substr(6), 10)) } }

using this you'll have inside your model a Date object that ExtJs will use at its best.
It's an hack, I know and I don't like it but it works and it doesn't violate too many rules.

Bye

Crockford
26 Sep 2011, 7:22 AM
Try this:


{ name: 'opened', type: 'date', dateFormat: 'MS' },

MS is a special format for Microsoft AJAX serialized dates.

See Ext.Date (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date).

HTH

You are missing the point.
The problem is not formatting but converting date. The microsoft serializazion date format need to be converted to Date object, first of all.
Too much problems if you avoid this.

Bye

twaindev
26 Sep 2011, 8:11 AM
@Crockford,

On fields in a store or model the dateFormat (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Field-cfg-dateFormat) config is used to specify how the date should be converted to a Date object.
'MS' is the converter for Microsoft AJAX serialized dates. Have a look at src/core/src/lang/Date.js.

Crockford
26 Sep 2011, 8:28 AM
@Crockford,

On fields in a store or model the dateFormat (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Field-cfg-dateFormat) config is used to specify how the date should be converted to a Date object.
'MS' is the converter for Microsoft AJAX serialized dates. Have a look at src/core/src/lang/Date.js.

You are absolutely right.
An Ext.data.Field type can be enriched with property dateFormat that I didn't known. I have to skill up with that documentation.

{ name : 'opened', type: 'date', dateFormat: 'MS' }

Personally tested. It works.

nobruds
22 Sep 2014, 11:31 AM
But that way displays the date on my grid panel like = 'Thu Feb 19 00:00:00 UTC-0200 2015',

how can I change to D/M/Y ?

My store { name: 'Date', type: 'date', dateFormat: 'MS' },
My Grid column { id: 'Date', dataIndex: 'Date', header: 'Date', width: 80 },