How to get jQuery Tablesorter to sort descending by default?

Matt McCormick picture Matt McCormick · Oct 23, 2009 · Viewed 22.1k times · Source

I can't figure this out. This question was also asked here http://www.nabble.com/TableSorter-plugin---default-column-sort-DESC-instead--How--to25180761s27240.html#a25180761 with no response.

I've tried

    $.tablesorter.defaults.sortInitialOrder = 'desc';

and altering the jquery.tablesorter.js file to default to 'desc' but it doesn't work. When I click on the column headers, the first sort is still ascending so the user has to click twice to descend the values.

How can I get Tablesorter to sort by descending by default?

Answer

Sean picture Sean · May 17, 2011

Try the latest version from the tablesorter site - this seems to be fixed somewhere between version 2.0.3 and 2.0.5.

<script type="text/javascript">
$(document).ready(function() 
    { 
        $("#theTable").tablesorter({ 
            sortInitialOrder: 'desc',
            sortList: [[3,1]] // etc.

    }); 
    } 
); 
</script>

...that worked with the latest version of tablesorter, but didn't with the previous one I had. Hope it helps!