views:

74

answers:

2

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?

+1  A: 

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' 
            } 
        } 
    }); 
});  
Andy E
A: 

now its not sorting at all, pls help me out, its urgent, thanks in advance :)

Mahesh Varia
@Mahesh Varia: You should use the "add comment" links below answers to leave a comment. Do you mean no fields are sorting now or just the date field is not sorting?
Andy E