我有一个带日期列的Dojo Grid。尽管使用自定义格式化程序,它总是进行字符串排序。请注意,我的传入日期将格式化为02/17/2005,我无法更改。
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>
Per 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'
}
答案 0 :(得分:0)
看看example in the docs。我认为你只需要使用ISO格式的日期(yyyy-mm-dd),这通常是很好的做法。您也可以传入本机Date对象,但字符串显然更具可移植性。
答案 1 :(得分:0)
瘦,你需要一个WriteStore而不是一个ReadStore