maa*_*aaz 4 javascript jquery tablesorter jquery-plugins
我正在使用Tablesorter插件对表进行排序.第四列是具有格式的日期字段:
- > 2013年1月30日
- > 2013年2月1日
当我尝试排序格式时,它会给出错误的排序.
我的查看页面:(日期栏之一)
<td onclick="viewTrainingeDetails(${privateTrainingInstance?.id})"><g:formatDate format="dd MMM yyyy" date="${privateTrainingInstance?.startDate}" /></td>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$(function() {
$("#myTable").tablesorter();
});
Run Code Online (Sandbox Code Playgroud)
Mot*_*tie 13
尝试添加此自定义解析器(演示):
$.tablesorter.addParser({
id: "date",
is: function (s) {
return false;
},
format: function (s, table) {
return new Date(s).getTime() || '';
},
type: "numeric"
});
Run Code Online (Sandbox Code Playgroud)
然后像这样初始化插件:
$('table').tablesorter({
headers: {
5: { sorter: 'date' }
}
});
Run Code Online (Sandbox Code Playgroud)
更新:为获得最佳效果,请确保返回有效日期:
$.tablesorter.addParser({
id: "date",
is: function (s) {
return false;
},
format: function (s, table) {
var date = new Date(s);
return date instanceof Date && isFinite(date) ? date.getTime() : '';
},
type: "numeric"
});
Run Code Online (Sandbox Code Playgroud)