-
11 Apr 2012 10:44 PM #1
Answered: Store Date Field / Grid Date Column Not Displaying Time Correctly
Answered: Store Date Field / Grid Date Column Not Displaying Time Correctly
Hi there,
So I know in terms of my title that with using date you have to be very specific (format wise) otherwise the outcome will not be as desired.
However, currently, I am using an ajax request associated with a store which is retrieving the following date format back in json such that the actual date is for example...
"2012-4-12 10:34:00 PM"
In my store, I have defined the field to be...
Displaying this format in the grid (using this store) has been perfect, however, my objective is to also display the time as well so I attempted to change the date format of the store field to ...Code:[ { name: 'Begin Date', type: 'date' format: 'Y-m-d' }]
and adjusted the grid date column format to...Code:[ { name: 'Begin Date', type: 'date' format: 'Y-m-d H:i:s' }]
and now the "Begin Date" column is not displaying any data at all.Code:'Y-m-d H:i:s'
All examples I have read about online only show store date type field's using the format 'Y-m-d' so I'm wondering if it's even possible to define the date time in the store with such as defined above, I don't see why not.
The store is set to autoload the grid on app launch.
Thanks for any assistance.
-
Best Answer Posted by vietits
FYI: The following code works well on Chrome, Ext 4.0.7.
Code:Ext.onReady(function(){ var store = Ext.create('Ext.data.Store', { fields: [{ name: 'begin', type: 'date', dateFormat: 'Y-n-d h:i:s A' }] }); store.add({begin: '2012-4-12 10:34:00 PM'}); var grid = Ext.create('Ext.grid.Panel',{ renderTo: Ext.getBody(), width: 300, height: 200, store: store, columns:[{ xtype: 'datecolumn', header: 'Begin', dataIndex: 'begin', format: 'Y-m-d H:i:s', flex: 1 }] }); });
-
11 Apr 2012 11:04 PM #2
FYI: The following code works well on Chrome, Ext 4.0.7.
Code:Ext.onReady(function(){ var store = Ext.create('Ext.data.Store', { fields: [{ name: 'begin', type: 'date', dateFormat: 'Y-n-d h:i:s A' }] }); store.add({begin: '2012-4-12 10:34:00 PM'}); var grid = Ext.create('Ext.grid.Panel',{ renderTo: Ext.getBody(), width: 300, height: 200, store: store, columns:[{ xtype: 'datecolumn', header: 'Begin', dataIndex: 'begin', format: 'Y-m-d H:i:s', flex: 1 }] }); });
-
12 Apr 2012 8:17 AM #3
Thanks vietits,
It was a simple mistake of not re-verifying what was being passed in as a request.
The time was being passed in as "2012-4-12 10:34:00:0 PM"
Instead of "2012-4-12 10:34:00 PM".
Once that was fixed, it was working correctly.


Reply With Quote