日付列を持つ Dojo Grid があります。カスタム フォーマッタを使用しているにもかかわらず、常に文字列の並べ替えが行われます。受信日は 2005 年 2 月 17 日のようにフォーマットされ、変更できないことに注意してください。
formatDate = function(d){
return dojo.date.locale.format(new Date(d), {datePattern: "M/dd/yyyy", formatLength: 'short', selector: "date"});
}
var myData= [
{field: "transactionDate", name: "Transaction Date", width: "115px", datatype: "date", formatter: formatDate },
{field: "description", name: "Transaction Description", width: "170px" },
]];
var storeData = {
items: [
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"02/15/2010",
description:"A description of the transaction"
}
,
{
transactionDate:"01/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"09/15/2009",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
,
{
transactionDate:"04/15/2011",
description:"A description of the transaction"
}
]};
<div class="claro" style="width: 835px; height: 300px;">
<div dojotype="dojo.data.ItemFileReadStore" jsID="dataStoreForGrid" data="storeData"></div>
<div id="grid" dojotype="dojox.grid.DataGrid" store="transferStoreForGrid" clientSort="true" jsID="SomeId" structure="myData" rowsperpage="40" ></div>
</div>
Peller の提案に従って、ISO 日付として書式設定してみました。タイ人はソートに影響を与えませんでした:
formatDate = function(d){
var d2 = dojo.date.stamp.fromISOString(ISODateString(new Date(d)));
return dojo.date.locale.format(d2, {selector: 'date', formatLength: 'long'});
}
function ISODateString(d) {
function pad(n){
return n<10 ? '0'+n : n
}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
}