NewBoy
NewBoy

Reputation: 1144

How to correct sorting orders using Jquery Data table

I am currently using the Jquery Plug DataTables I am trying to figure out i can display my data from desc to asc. I have checked through the documentation i can not find anything thing clear that enables me to solve this problem. i've also added a link to my site here

I have a added a snippet of my JS here

$(".sortable").DataTable({order: asc});

Upvotes: 0

Views: 46

Answers (3)

Rana
Rana

Reputation: 1218

From the documentation of order option , the value of order option has to be array of arrays

The order must be an array of arrays, each inner array comprised of two elements

 $(".sortable").DataTable( {
    "order": [[ x, "asc" ]]
} );

where x is the index of the column that you want to order by

Upvotes: 2

omarjmh
omarjmh

Reputation: 13896

You code is close, as far as the example you have shown, the issue is that the order needs to be an array, not only the string 'asc' and DataTable should be dataTable:

$(".sortable").DataTable({order: asc});

should be:

$(".sortable").dataTable({
    "order": [[0, 'asc']]
});

Link to order docs

Upvotes: 0

blurfus
blurfus

Reputation: 14031

From their docs:

$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 3, "desc" ]]
    } );
} );

Columns are ordered using 0 as the index for the first column on the left.

For multi-column sorting, you could have something like:

order: [[ 3, 'desc' ], [ 0, 'asc' ]]

Upvotes: 0

Related Questions