By default the ExtJS datefield uses the same format string for both the parsing (data reading) and formatting (data displaying) functions.
I wanted to display a different format than the data format of the data. My data comes from the server in the format “Y-m-d H:i:s.u” but I wanted to display as ‘Y-m-d’ or in some cases just ‘M Y’. In my mind this should be a fairly easy thing…. after a lot of looking around on the internet the solution most often presented seemed to be: extend datefield and override the parse and format methods on the datefield.
This to seemed ridiculously complicated for something that should be built in. Finally I came up with a nice simple solution that was probably the one intended by the Ext team.
The solution is to simply declare the output format as format and the input format as the altFormats so for me
…,
format:’Y-m-d’,
altFormats:’Y-m-d H:i:s.u’,
…
in this way Ext will use the format of ‘Y-m-d’ for display and when parsing it will fail with that format and the try with the first (and only in this case) alt format of ‘Y-m-d H:i:s.u’
I’m not sure why this is not documented in the Ext documentation but seemed the simplest solution to the problem.
