开发者

dd.mm.yyyy format in jQuery tableSorter

I'd like to add a parser to jQuery TableSorter which allows a column to be sorted by date on the 开发者_Python百科dd.mm.yyyy format, for instance 17.09.2011.

I tried the following, based on some code I found online:

$.tablesorter.addParser({
    // set a unique id 
    id: 'myDateFormat',
    is: function (s) {
        return false;
    },
    format: function (s) {
        var date = s.split('.');
        return new Date(date[2], date[1], date[0]).getTime();
    },
    type: 'numeric'
}); 

Then:

$(".myTable").tablesorter( { headers: { 3: { sorter: 'myDateFormat'} } } );

However, this doesn't work... Any idea why?

Thank you!


It seems to work for me - demo

The demo is using my forked version of tablesorter, but that shouldn't change how your parser works.


try

// add parser through the tablesorter addParser method
$.tablesorter.addParser({
    // set a unique id 
    id: 'clDate',
    is: function (s) {
        // return false so this parser is not auto detected 
        return false;
    },
    format: function (s) {
        // format your data for normalization 
        var date = s.split("-");
        var result = (parseInt(date[2]) * 10000 + parseInt(date[1]) * 100 + parseInt(date[0]));
        return result;
    },
    // set type, either numeric or text 
    type: 'numeric'
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜