PDA

View Full Version : String Date to ExtJS Date Formatted



harman
12 Sep 2012, 8:13 AM
Hi,

I have a Date field that comes to me as a String in JSON like

"09-05-2012 7:33 AM"
I have to show it as a Date with the same format in my Grid column.
(I am converting it to date as grid column does not sort it as Date but String)
How do i do it?
If i do this in my model

{name: 'someDate', type: 'String', convert:function(value, records){ var rcptDate=new Date(value);
return Ext.Date.format(rcptDate, 'm-d-Y g:i A');
}}
i get value like NaN-NaN-0NaN 12:NaN PM

What am i doing wrong?
Or is it that it cant be converted?

droessner
12 Sep 2012, 9:57 AM
You can define the field in the store as follows:



{
name: 'someDate',
type: 'date',
dateFormat: 'm-d-Y g:i A'
}


and then put the following renderer on your grid column:



renderer: Ext.util.Format.dateRenderer('m-d-Y g:i A')

Tim Toady
12 Sep 2012, 11:24 AM
I would also use the date type for the field as droessner stated, but I would be slightly more lazy and use the datecolumn (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.column.Date)

harman
12 Sep 2012, 11:42 PM
Thanks droessner,

Exactly what i wanted. =D>
However i will need a little more testing to see if the Sorting works correctly.

daklan
29 Mar 2018, 6:24 AM
Thanks a lot

daklan
29 Mar 2018, 6:25 AM
You can define the field in the store as follows:



{
name: 'someDate',
type: 'date',
dateFormat: 'm-d-Y g:i A'
}


and then put the following renderer on your grid column:



renderer: Ext.util.Format.dateRenderer('m-d-Y g:i A')



Thanks a lot : )