Gracie williams
Gracie williams

Reputation: 1145

How to sort two columns at once in datatables

I have a table like below , I want to sort column A ascending and column B descending.

A B C 1 4 string1 2 11 string2 1 13 string3 2 43 string4

And, I want to sort by both A (ascending) and B (descending) at once, to get this:

A B C 1 13 string3 1 4 string1 2 43 string4 2 11 string2

Right now I can able to sort one column with following code

oTable.api().columns( ['.acol'] ).order("asc").draw();

Upvotes: 0

Views: 60

Answers (1)

ymz
ymz

Reputation: 6914

From the docs:

You can specify multiple columns in order command. In your case:

oTable.api().columns( ['.acol', '.bcol'] )
            .order([ [ '.acol', 'asc' ], [ '.bcol', 'desc' ] ])
            .draw();

Upvotes: 1

Related Questions