开发者

sorting on formatted date in jquery

I am trying to sort a table which has column like 01 Apr 2010. I am using below to apply sort

$(document).ready(function() 
{ 
    $("#dataTable").tablesorter();  
});

But its not working for the dates of format dd MMM yy. Can any one suggest how can i apply this 开发者_如何学编程format for sorting?


Check out the example parsers page, it shows you how to create a custom parser. You can parse dates like that with new Date(date) or Date.parse(date). I don't have the means to test it, but something like this should work:

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'ddMMMyy', 
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) { 
        // parse the string as a date and return it as a number 
        return +new Date(s);
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

All that's left for you to do is specify the sorting method using the headers option:

$(document).ready(function() { 
    $("dataTable").tablesorter({ 
        headers: { 
            6: { // <-- replace 6 with the zero-based index of your column
                sorter:'ddMMMyy' 
            } 
        } 
    }); 
});  
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜