开发者

Jquery tablesorter for different date format

In jQuery table sorter doc http://tablesorter.com/docs/ we have date in Jan 18, 2001 9:12 AM this format.

If I am ch开发者_运维问答anging this date to January 12, 2010 format then sorting is not happening.

Can anyone please help?


Jquery tablesorter plugin understands usLongDate and shordDate Date formats by-default.

That's why it is not understanding January 12, 2010 format.if you really want to use this format then the right thing to do would be to add your own parser for this custom format.

check out the link to help you how to write custom parser.

In the tablesorter source, find out the shortDate and usLongDate format parser and try to add your custom parser too.

jquery.tablesorter.js

You can also try this one, it should work,

ts.addParser({
        id: "customDate",
        is: function(s) {
            return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, [0-9]{4}|'?[0-9]{2}$/));
        },
        format: function(s) {
            return $.tablesorter.formatFloat(new Date(s).getTime());
        },
        type: "numeric"
    });

when you add it into your tablesorter source and refresh the table in the browser, it automatically identify the column and sorting will work. if it will not work then apply it to the column where you have this format, like

$(function() {
    $("table").tablesorter({
        headers: {
            4: { sorter:'customDate' }
        }
    });
}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜