Jquery:TableSorter-具有特定格式的日期不起作用(Jquery: TableSorter- Date with specic format is not working)
我正在使用Tablesorter插件对表格进行排序。 第四列是具有以下格式的日期字段:
- > 2013年1月30日
- > 01二月2013
当我尝试排序格式时会给出错误的排序。
我的查看页面:(日期栏之一)
<td onclick="viewTrainingeDetails(${privateTrainingInstance?.id})"><g:formatDate format="dd MMM yyyy" date="${privateTrainingInstance?.startDate}" /></td>jQuery的
$(function() { $("#myTable").tablesorter(); });I am using Tablesorter plugin to sort the table . fourth column is date fields having format :
-->30 Jan 2013
-->01 Feb 2013
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(); });最满意答案
尝试添加此自定义分析器( 演示 ):
$.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" });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" });更多推荐
发布评论