Show data is sorted when not sorted by dataTables

Show data is sorted when not sorted by dataTables

simonvanesimonvane Posts: 2Questions: 1Answers: 0

The data for my table is pre-sorted so I don't want the overhead of dataTables doing the first sort. I have set aaSorting to [] so that dataTables does not sort the data.

My problem is that I would like the header style to show which column the data is sorted by and when that column is sorted for it to toggle the sort order.

I tried a cheat of the following which displays the way I want but I have to click twice to change the search to descending.

    dataTableOptions.fnInitComplete = function (oSettings, json) {
        $table.find('th:first').addClass('sorting_asc');
    };

Any suggestions would be greatly appreciated.

Thanks.

Answers

  • simonvanesimonvane Posts: 2Questions: 1Answers: 0

    A solution to this problem is:

    $(document).ready( function() {
    $('table').dataTable( {
    "aaSorting": [],
    "aoColumns": [
    { "asSorting": [ "desc", "asc" ] }
    ],
    fnInitComplete: function (oSettings, json) {
    $('table').find('th:first').addClass('sorting_asc');
    }
    } );
    } );

    See http://jsfiddle.net/259r8/4/

This discussion has been closed.