Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consuming JSON dates in a EXTJs gridpanel

Tags:

c#

extjs

I have a object that im serializing to a JSON object using JSON.Net. This object is then being consumed by a JSON Store which is attached to a ExtJs GridPanel.

All fields except date fields render fine , the only way i can render date fields is if i use text columns. But then i get the following /Date(1293746400000+0200)/ rendered as text which is useless.

I know i need to convert that somehow to a proper date object but i have not idea how atm.

Let me know if you need more info.

like image 473
RC1140 Avatar asked Oct 12 '09 18:10

RC1140


3 Answers

"M$" in the preceeding example is misleading, its "MS". Here is a clear example that works in extjs 4. The 'LastFellOffCliff' field is set to be a date with incoming format in the Microsoft JSON date style: "/Date(...)/"

Ext.define('ACME.model.CoyoteModel', {
    extend: 'Ext.data.Model',
    fields: [
                { name: 'CoyoteID', type: 'int' },
                'Nickname',
                { name: 'LastFellOffCliff', type: 'date',  dateFormat: 'MS'  },
                'Notes'
            ]

});
like image 186
Brett Avatar answered Nov 11 '22 11:11

Brett


JSON.Net has various date/time converters to help you deal with this. See this blog post for some details. So you could use the JavaScriptDateTimeConverter for example, then eval the result into a JS date object. I can't recall off the top of my head how an Ext store will deal with that, but maybe it will point you in the right direction.

like image 42
Brian Moeskau Avatar answered Nov 11 '22 11:11

Brian Moeskau


Have a look at here.

In most cases you can pass your own formatted string (i use "yyyy-MM-dd" in my projects as i don't need time) and re-use it on the other side (format it as a valid date constructor).

like image 23
Alex Bagnolini Avatar answered Nov 11 '22 11:11

Alex Bagnolini