2
我試圖理清其中有像列04月01日表2010年我使用下面的鏈接申請排序排序上被格式化的日期的jQuery
$(document).ready(function()
{
$("#dataTable").tablesorter();
});
但它不工作的格式DD MMM YY的日期。任何人都可以建議我如何應用這種格式進行排序?
我試圖理清其中有像列04月01日表2010年我使用下面的鏈接申請排序排序上被格式化的日期的jQuery
$(document).ready(function()
{
$("#dataTable").tablesorter();
});
但它不工作的格式DD MMM YY的日期。任何人都可以建議我如何應用這種格式進行排序?
查看example parsers page,它向您展示瞭如何創建自定義分析器。你可以使用new Date(date)
或Date.parse(date)
解析日期。我沒有測試它的手段,但這樣的事情應該工作:
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'ddMMMyy',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// parse the string as a date and return it as a number
return +new Date(s);
},
// set type, either numeric or text
type: 'numeric'
});
爲你做所有剩下的就是使用headers
選項指定排序方法:
$(document).ready(function() {
$("dataTable").tablesorter({
headers: {
6: { // <-- replace 6 with the zero-based index of your column
sorter:'ddMMMyy'
}
}
});
});