Jquery:TableSorter-具有特定格式的日期不起作用 [英] Jquery: TableSorter- Date with specic format is not working
本文介绍了Jquery:TableSorter-具有特定格式的日期不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Tablesorter 插件对表格进行排序。
第四列是格式为的日期字段:
I am using Tablesorter plugin to sort the table . fourth column is date fields having format :
- > 2013年1月30日
- > 2013年2月1日
当我尝试排序格式时,它会给出错误的排序。
when i try to sort format it gives wrong sorting.
我的查看页面:(其中一个日期栏)
My View page:(one of the date column )
<td onclick="viewTrainingeDetails(${privateTrainingInstance?.id})"><g:formatDate format="dd MMM yyyy" date="${privateTrainingInstance?.startDate}" /></td>
jquery
$(function() {
$("#myTable").tablesorter();
});
推荐答案
尝试添加此自定义解析器(演示):
Try adding this custom parser (demo):
$.tablesorter.addParser({
id: "date",
is: function (s) {
return false;
},
format: function (s, table) {
return new Date(s).getTime() || '';
},
type: "numeric"
});
然后像这样初始化插件:
then initialize the plugin like this:
$('table').tablesorter({
headers: {
5: { sorter: 'date' }
}
});
更新:为了获得最佳效果,请确保您是返回有效日期:
Update: for best results, make sure you are returning a valid 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"
});
这篇关于Jquery:TableSorter-具有特定格式的日期不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文