View Full Version : Date format ignored

30 May 2007, 9:52 AM
I have a date field in a grid:

var cols = new G.ColumnModel([{
header : 'Date Posted' ,
dataIndex : 'DatePosted' ,
width : 150 ,
editor : new GE(new F.DateField({
format : 'Y-m-d g:i:s'
} , { ....

The data for the grid is loading fine, it shows

"2007-05-21 14:59:21"

for instance. However as soon as I edit the date it changes to

"Mon May 21 2007 02:29:32 GMT-0400 (Eastern Daylight Time)"

Any ideas what I'm doing wrong/how to fix this?

30 May 2007, 10:30 PM
That's because the value returned by an edit is always a date object. For a column with dates, you will want to have a date renderer + your data field defined as a date. Take a look at the editor grid example, it does exactly that.

31 May 2007, 8:55 AM

One more problem, however...

The data in record.data['DatePosted'] still = "Mon May 21 2007 02:29:32 GMT-0400 (Eastern Daylight Time)". Is there any way to get the data that is currently in the grid other than re-applying the format when you pull the data? I'd be okay doing this except that I have a function that generates JSON output based on new/edited fields and pulling from Record.fields.map[field].dateFormat to format the date seems rather convoluted and inefficient since dates likely aren't the only type of field doing this?

thanks again

31 May 2007, 9:43 AM
It's stored as a Date object rather than a string b/c you might need to do multiple operations on it e.g. timespan, format as just a date in one place and timestamp in another, or make it locale specific. It's easier to do all this off a Date object rather than having to parse some string value to do things. If you really don't want to do this, treat your date as a string when you load your store, then you'll have to convert to/from Date before/after you edit.

31 May 2007, 11:48 AM
Right, I guess what I'm asking is if there's a function that gets the data as the grid shows it, ie record.getFormattedDate('DatePosted') or something.

If there's not, I'm going to write one, it just seems like something that might already have been done.

31 May 2007, 11:59 AM
The Record object won't know about the formatting. You could get it from the grid cell or you could pass the record value back thru the renderer you specified on the colModel as you serialize for upload.

1 Jun 2007, 5:27 AM
The record does know about the formatting, though. Record.fields.map[field].dateFormat exists. I ended up adding Record.getFormattedValue() which checks this then defaults to Record.get(). The problem I have with this is that I'm not sure if dates are the only fields that can have formatting applied like this. I'm not as worried about records that have custom display functions, like color hilighting, etc.