PDA

View Full Version : ExtJS Date column issue in MVC



Pravin.Pawar
14 Dec 2012, 4:46 AM
Hi,

I'm using MVC and returning JsonResult somehow the date columns are showing following values for the dates-

/Date(1350294780000)/

In ExtJS model; I have used string type and if I use date then grid do NOT display data.

Please let me know if you are aware about the solution.

friend
14 Dec 2012, 5:18 AM
The field declaration in your model should look something like this:


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

You can then set a renderer on a grid column for whatever visual formatting you like.

Functional example:




var store = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: [
{name: 'myDate', type: 'date', dateFormat: 'MS'}
],
data: [{
myDate: '/Date(1350294780000)/'
},{
myDate: '/Date(1350644780000)/'
},{
myDate: '/Date(1350894780000)/'
}]
});

var grid = Ext.create('Ext.grid.Panel', {
columns: [{
header: 'My Date', dataIndex: 'myDate', width: 100, renderer: Ext.util.Format.dateRenderer('m/d/Y')
}],
store: store
});

Ext.create('Ext.window.Window', {
height: 180,
width: 400,
items: [grid]
}).show();

Pravin.Pawar
14 Dec 2012, 5:26 AM
Thanks for quick reply... where can I see other date formats because I want date in "mm/dd/yyyy hh:mm:ss"

Pravin.Pawar
14 Dec 2012, 5:30 AM
Yes, when I applied date format on renderer then it works fine-

renderer: function (val) {
val = Ext.util.Format.date(val, 'm/d/Y g:i:s A');
return val;
}

is there any other way where we can resolve issue without using render?

friend
14 Dec 2012, 5:33 AM
On the server-side, you can usually configure your JSON serialization to emit dates in a desired format. Then just treat them as plain old Strings on the client side.

pcr
15 Dec 2012, 3:53 AM
I use moments.js for all my cliŽntsysteem dateparsing and formatting. Look at: momentjs.com