Jquery:TableSorter

编程入门 行业动态 更新时间:2024-10-25 07:31:35
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" });

更多推荐

本文发布于:2023-08-04 16:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Jquery   TableSorter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!