Jquery:TableSorter-具有特定格式的日期不起作用

我正在使用Tablesorter插件对表进行排序。 第四列是具有格式的日期字段:

– > 2013年1月30日

– > 2013年2月1日

当我尝试排序格式时,它会给出错误的排序。

我的查看页面:(其中一个日期列)

 

jQuery的

  $(function() { $("#myTable").tablesorter(); }); 

尝试添加此自定义解析器( 演示 ):

 $.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" });