views:

68

answers:

2

Hi,

I am using a datatable loaded via JSON with date like this : 2010-06-03 With Opera and Chrome I have the correct date displayed as 06/03/2010. With Firefox Windows (even in safe mode, without any plug-in), I get a NaN/NaN/NaN. If I use the debug console, I see a valid date, but in Firefox Windows I can see a "Invalid date". Bonus, with Firefox Mac awith a ton of plug-ins, we have the valid date!

Here is the setting of the date column

oColumn['editor'] = 
   new YAHOO.widget.DateCellEditor({asyncSubmitter:UpdateRowData});
oColumn['formatter'] = YAHOO.widget.DataTable.formatDate;
oField['parser'] = 'date';

Thanks,
Cédric

+2  A: 

Turns out that "2010-06-03" does not return an valid Date object (at least in FF/Win). For cross-browser compatibility, be sure your value is in a format acceptable to the Date constructor: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date

Jenny Donnelly
You are rigth : Firefox 3.5 do not accept yyyy-mm-dd as a date for Date constructor... but Firefox 3.6 accept it!I solved the bug by creating a specific date parser for date cells of my datatable.
Cédric Girard
A: 

Depending on your situation, another way to solve this is to include an actual date constructor in your "JSON" data. Once you do so, it's no longer standard JSON and you'll need to eval it on the browser.

Eg

{'duration': 75, 'end_time': new Date(Date.UTC(2008,11,23,17,45,00,0)),
 'start_time': new Date(Date.UTC(2008,11,23,16,30,00,0))}

The benefit is no longer any need to parse the data on the browser since the datum is already a date object.

The downside is that you're no longer sending valid JSON from your server to your client browsers.

Larry K