Search code examples
dojodojox.griddojox.grid.datagrid

dojox.grid.DataGrid custom sort method?


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


Solution

  • 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!!