jquery tablesorter プラグインを使用してテーブルをソートしています。テーブルの列の 1 つに、日付が mm/yy 形式で表示されます。
<tr>
<td class="col-name">...</td>
...
<td rel="2000" class="col-dob">10/00</td>
...
</tr>
<tr>
<td class="col-name">...</td>
...
<td rel="1986" class="col-dob">11/86</td>
...
</tr>
ノート:
- 各セルには固有のクラスがあります
- 日付は mm/yy 形式で表示されます
- 日付のあるセルには年も表示されます
私のjQueryコードは次のとおりです。
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'user-birthdate',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
var dateSplit = s.split('/');
if(2 !== dateSplit.length)
return 0;
return new Date(dateSplit[1], dateSplit[0], 1);
},
// set type, either numeric or text
type: 'numeric'
});
myClass.init = function() {
$('.module .user table').tablesorter({
sortList: [[0,0]],
widgets: ['zebra'],
headers: {
5: {
sorter:'user-birthdate'
}
}
});
}
myClass.init();
私の問題は、tableSorter が 00 を 2000 年ではなく 1900 年として解釈するため、ソートされたデータが正しくないことです。
どうすればこれを解決できますか?jQuery 1.2.6 と最新バージョンの tablesorter を使用しています。