Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the date format in a grid field ExtJS

Tags:

date

extjs

extjs4

simple question but I can't figure out how to resolve it.

I'm receiving a date with hour from JSON with this format :

"date_deb":"2013\/12\/28 23:00:00"

Note that the \ are for escaping the / and are not displayed. I would like to display this dates in this format into my grid :

"28/12/2013 23:00:00"

I've tried this into my fields definition:

{name:'date_deb', type: 'date', dateFormat: 'd-m-Y H:i:s'}

But it's not working, nothing is displayed. By checking the ExtJS docs, I've seen this :

dateReadFormat

I'm using ExtJS4.2

like image 370
Stranded Kid Avatar asked Feb 07 '14 09:02

Stranded Kid


2 Answers

In your field definition provide the dateFormat as it is returned from the server:

{name:'date_deb', type: 'date', dateFormat: 'Y/m/d H:i:s'}

and then in your column config use ExtJS's built-in dateRenderer with the format you'd like to render your dates with:

renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s')

You'll only need dateReadFormat and dateWriteFormat if you have a reader (to read data from server) AND a writer (to send modified data back to server) which need different date formats. Otherwise dateFormat will apply as the default format for both.

like image 111
matt Avatar answered Nov 11 '22 06:11

matt


If the above doesn't work for you, try adding xtype: 'datecolumn' in your grid's 'columns' config.

columns: [{
            text : 'date',
            dataIndex: 'LoginDateTime',
            xtype: 'datecolumn',
            format: 'Y-m-d g:i A',
}]

This should work.

like image 20
user1463110 Avatar answered Nov 11 '22 08:11

user1463110