Search code examples
jquerysortingdatatables

Jquery DataTables change order to desc when it sorts


I am using DataTables to display some data and it works great but I want to customize it slightly and not sure how.

What I want to do is when a user clicks on a column heading to sort that column I want it to initially order descendingly rather than ascendingly. Is there any way to do this?


Solution

  • Have a look at this: DataTables sorting direction control example

    You can do something like:

    $(document).ready(function() {
        $('#example').dataTable( {
            "aoColumns": [
                { "asSorting": [ "desc", "asc" ] }, //first sort desc, then asc
            ]
        } );
    } );