RC1140
RC1140

Reputation: 8663

Consuming JSON dates in a EXTJs gridpanel

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.

Upvotes: 6

Views: 4628

Answers (4)

Brett
Brett

Reputation: 71

"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'
            ]

});

Upvotes: 7

Jonathan Bates
Jonathan Bates

Reputation: 1835

In the field(s) that is/are for the date in your JsonStore, you can set the field's type to 'date' and its dateFormat to 'M$'. Works like a champ.

Upvotes: 0

Alex Bagnolini
Alex Bagnolini

Reputation: 22392

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).

Upvotes: 1

Brian Moeskau
Brian Moeskau

Reputation: 20431

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.

Upvotes: 1

Related Questions