1

I am trying to give a the second column in our data table sorting from biggest to smallest/ I have tried the following without success.

  $(".one-table").dataTable({
           "bRetrieve": false,
          "bFilter": false,
          "iDisplayLength":4,
          "bLengthChange": false,
          "bJQueryUI": true,
     "bAutoWidth":false,
      "aoColumns": [
        { "asSorting": [ "asc" ], "aTargets": [ 2 ]},
        { "asSorting": [ "desc" ], "aTargets": [ 1 ]} ]
        });

Whilst this works for setting the default sorting direction, it does not allow us to sort the default column. I have also tried iDataSort

Datatables API says to use $(document).ready(function() {

  var oTable = $('#example').dataTable();

  // Sort immediately with columns 0 and 1
  oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
} );

But this just creates errors

The next version I tried

>   var clTable;
>               clTable =  $(".one-table").dataTable({       "bRetrieve": false,
>           "bFilter": false,
>           "iDisplayLength":4,
>           "bLengthChange": false,
>           "bJQueryUI": true 
>   
>         
>         });
>             clTable.fnSort( [ [1,'asc'] ] );

1 Answer 1

1

I believe not this :

clTable.fnSort( [ [1,'asc'] ] );

but this:

clTable.fnSort( [1,'asc'] );
Sign up to request clarification or add additional context in comments.

3 Comments

thank you! Sorting by hand after creation is not what I was looking for but is more than adequate to the task!
@veeTrain you're welcome. You can already sort the result in your query :)
Thanks for the pointer, except that my users get to decide the order of the columns so I don't want to order my query by whatever column they select as 'first' when I can have the table just skip the 0th column (which I hide -- and which was being sorted upon any way) and sort on whatever is the first column instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.