views:

273

answers:

3
+1  A: 

You should specify the type of the column. Otherwise it will be sorted as text. You can do it by specyfing sorter parameter:

<table>
<thead>
    <tr>
        <th>Id</th>
        ... other columns ....
        <th class="{sorter: 'isoDate'}">Date</th>
</tr>   
</thead>
<tbody>
... table body ....

Alhough I'm not sure if isoDate is the sorter you should use, but tablesorter have two other sorters: usLongDate and shortDate. You can try which one of those will do the job.

Lukasz Lysik
Works too indeed, thanks!
Mike K.
A: 

If none of the default date sorting options work, try using a custom parser and converting the date to it's equivalent millisecond representation for sorting.

$.tablesorter.addParser({ 
    // set a unique id 
    id: 'dateMS', 
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) { 
        var d = Date.parse(s);
        if (isNaN(d)) {
           return -1;
        }
        return d;
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
});     

$(function() { 
    $("table").tablesorter({ 
        headers: { 
            6: { 
                sorter:'dateMS' 
            } 
        } 
    }); 
});
tvanfosson
Thanks! But disabling the internal auto-detect from tablesorter does the trick also. He was reading my data as text.
Mike K.
+2  A: 

It's sorting based on alphanumeric (ASCII) values, not based on date-values (It will also put November before October). You need jquery to interpret each cell as a date value and then sort them accordingly. If their built-in type detection isn't working, you have to force the data type. See http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/ for more information.

Jason Yanowitz
Works great. I love the fact I have manual control over the columns. Thanks so much!
Mike K.