jureispro
jureispro

Reputation: 1402

Table sorting for DD-MM-YYY hh:mm:ss not working

I have problem with sorting datetime format DD-MM-YYY hh:mm:ss. I tried several codes that I found online and none of them worked. Does someone knows where's the problem?

Here is code that I am using:

("#resultsTable").tablesorter({
    2: {
        sorter: "shortDate",
        dateFormat: "uk"
    }
});

Upvotes: 3

Views: 999

Answers (1)

Janith Chinthana
Janith Chinthana

Reputation: 3844

You can do it with a addParser as code given below, This is simply convert time to numeric value and sort.

$.tablesorter.addParser({ 
    id: 'date_column', // ID of the date column
    is: function(s) { 
        return false; 
    }, 
    format: function(s) { // convert datetime to timestamp
        var dateParts = s.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/);
        date = new Date(dateParts[3], parseInt(dateParts[2], 10) - 1, dateParts[1], dateParts[4], dateParts[5]);
        return date.getTime();         
    }, 
    type: 'numeric' 
}); 

This is just a sample code for how to sort following date format

17-09-2013 10:08
date-month-year hour(24):minute

You need to convert it to the way you need, for more information refer this question.

Upvotes: 4

Related Questions