Skip to content Skip to sidebar Skip to footer

Tablesorter, Wont Sort By Date Correctly

Does the tablesorter behave differently if there is whitespace about? I'm pretty new to tablesorter but I was asked quickly to add it to a customers site (specifically to allow the

Solution 1:

Got it working.. phew

$.tablesorter.addParser({
id: 'dayMonthYear',
is: function(s) {
    return false;
},
format: function(s) {       

    s = $.trim(s.replace(/\s+/g, ' '));


    var date = s.match(/^(\d{1,2})[ ](\w{3})[ ](\d{4})$/);
    var day = String(date[1]);
    if (day.length == 1) { day = "0" + day;}        
    var month = monthNames[date[2]];
    var year = date[3];

    return sortableDate = '' + year + month + day;
},
type: 'numeric'  
});
var monthNames = {};
monthNames["Jan"] = "01";
monthNames["Feb"] = "02";
monthNames["Mar"] = "03";
monthNames["Apr"] = "04";
monthNames["May"] = "05";
monthNames["Jun"] = "06";
monthNames["Jul"] = "07";
monthNames["Aug"] = "08";
monthNames["Sep"] = "09";
monthNames["Oct"] = "10";
monthNames["Nov"] = "11";
monthNames["Dec"] = "12";

Post a Comment for "Tablesorter, Wont Sort By Date Correctly"