views:

35

answers:

2

I have a dojox.grid.DataGrid, and one of the columns has date data in it. e.g.

09:01:00 18/10/2010
09:03:00 18/10/2010
09:02:00 19/10/2010

When I click the heading and sort the column, I get this...

09:01:00 18/10/2010
09:02:00 19/10/2010    
09:03:00 18/10/2010

It has sorted on the String value, not sorting it as a date value, hence the 19th gets misplaced.

I'd like to have a custom sorter method, or someway to tell the grid about the data type that it renders.

var rawdataDeltaInfo = '[{'timestamp':'15:27:45 18/10/2010'}]';

<table id="gridDeltas" jsId="gridDeltas" dojoType="dojox.grid.DataGrid" store="deltaInfo"  clientSort="false" >
    <thead>
            <tr>
                <th field="timestamp" >Create Date</th>
            </tr>
    </thead>
</table>

The alternative is to find someway to encode the date into the JSON string, and have a custom formatter for the table column?

Can anyone help?

Thanks Jeff Porter

+1  A: 

I've changed the JSON to pass over the dataTime long value, not the formatted date String.

Then I've changed the dojox.grid.DataGrid to have a custom formatter for the date column.

dojo.require("dojo.date.locale");
formattedString = dojo.date.locale.format(new Date(jsonLongDate), {datePattern: "HH:mm:ss dd/MM/yyyy", selector: "date"});

and it works!!!

yea!!

jeff porter
+1  A: 

Best practice with JSON is to use ISO dates

2010-10-18T09:01:00
2010-10-18T09:03:00
2010-10-19T09:02:00

It's culturally neutral and sorts properly using plain text sorting.

With dojox.grid, you can then declare a formatter that translates this to a Date object, then generates a culturally appropriate representation of the date for display.

peller