View Full Version : grid and dateRenderer

5 Feb 2008, 7:40 AM
Hi Forum!

I couldn't find this problem via search, so perhaps any one has a little hint for me. I am getting some Json data and display this with my grid. Everything works fine, except the date. When I use no renderer, the date is displayed correctly as a string. But I am not sure if this will work with sorting.

This is the working header:

{header: "start", width: 75, sortable: true, dataIndex: 'START_DATE'}

This will output NaN.NaN.NaN

{header: "finish", width: 75, sortable: true, renderer: Ext.util.Format.dateRenderer('d.m.y'), dataIndex: 'END_DATE'}

This is my Json input:


I think this is a minor problem, but I just can't find my error. Is the format string wrong? Is there some kind of format-string list for Ext?

Any help is appreciated! Thanks.

5 Feb 2008, 7:43 AM
The data in your store is a string, so formatting it as a date it won't work.

Define your field as:

{name: 'START_DATE', type: 'date', dateFormat: 'd.m.y'}

5 Feb 2008, 8:01 AM
Thanks for this very quick answer.

So the renderer takes a dateobject? Mostly the data will be retrieved from a database, so its never a dateobject? Unfortunately, this is the case here. Is there a way to manipulate this string with dateFormat? Like dateFormat: 'd.m.yy' (to get the full year 2008 instead of 08)?

Or is this a task for the backend where the Json string is generated?

Thanks for your help!!

2 Jul 2008, 10:06 AM
Hi All:

I have a grid in which I need to display a date, The date is returned from my server as milliseconds from 1/1/1970. In my renderer I am using "Ext.util.Format.date(v,'M-d-Y')" and I get an error as:"Date.monthNames[A] has no properties" If I try to use a numeric representation I get NANs in all the fields. What am I doing wrong?


2 Jul 2008, 7:45 PM
first up, either check out the latest Date.js from SVN, or include the fixes posted here:
if you're using the official 2.1 download.

next, since there's no matching parse format in the Date class for milliseconds since the unix epoch, make sure you don't specify any dateFormat for the json string returned from the server.

{name: 'mydate', mapping: 'mydateFromServer', type: 'string'} // treat it as a plain string
// {name: 'mydate', mapping: 'mydateFromServer', type: 'int'} // or as an integer value if you want

once done, change your renderer to:

renderer: function(v) {
// divide value from server by 1000 to obtain the no. of seconds since unix epoch,
// parse the result to obtain a Date object, then format it using Date.format()
Date.parseDate((Math.floor(v / 1000), 'U').format('M-d-Y');