0

I have a Dojo Grid with a date column. Despite using a custom formatter, it always does a string sort. Note that my incoming dates will be formatted as 02/17/2005 and I cannot change that.

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's suggestion, I tried formatting as ISO date. Thais had no affect on sorting:

    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&lt;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'
}
4

2 回答 2

0

瘦,你需要一个 WriteStore 而不是 ReadStore

于 2011-11-05T23:28:46.113 回答
0

查看文档中的示例。我认为您只需要对日期使用 ISO 格式(yyyy-mm-dd),这通常是一种很好的做法。您也可以传入本机 Date 对象,但字符串显然更具可移植性。

于 2011-10-13T02:52:07.360 回答