我在用表格分类器 http://tablesorter.com/docs/对表格进行排序的插件。
第四列是日期字段,格式为:
-->2013 年 1 月 30 日
-->2013 年 2 月 1 日
当我尝试对格式进行排序时,它给出了错误的排序。
我的查看页面:(日期栏之一)
<td onclick="viewTrainingeDetails(${privateTrainingInstance?.id})"><g:formatDate format="dd MMM yyyy" date="${privateTrainingInstance?.startDate}" /></td>
jquery
$(function() {
$("#myTable").tablesorter();
});
尝试添加这个自定义解析器(demo http://jsfiddle.net/Mottie/eY8uH/361/):
$.tablesorter.addParser({
id: "date",
is: function (s) {
return false;
},
format: function (s, table) {
return new Date(s).getTime() || '';
},
type: "numeric"
});
然后像这样初始化插件:
$('table').tablesorter({
headers: {
5: { sorter: 'date' }
}
});
更新:为了获得最佳结果,请确保返回有效日期:
$.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"
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)