0

日付列を持つ 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&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

ドキュメントの例を見てください。日付(yyyy-mm-dd)にはISO形式を使用する必要があると思いますが、これはとにかく一般的には良い習慣です。ネイティブのDateオブジェクトも渡すことができる場合がありますが、文字列の方が明らかに移植性が高くなります。

于 2011-10-13T02:52:07.360 に答える
0

薄いので、ReadStore ではなく WriteStore が必要です

于 2011-11-05T23:28:46.113 に答える