문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

You can also give comparatorMap parameter for your store.

{fieldname: compareFunction} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top