is there a way to define a function in datatables order?
is there a way to define a function in datatables order?

Actually, I have 2 tables (pending and published) using datatables on the same page.
The order API , as I know, allows to choose only columns and sorting direction.
My data are sorted now depending on closing date for both tables
order : [ 5, "desc" ]
Is there a way to choose the sorting column depending on the result of a function? For exemple:
order : function(){
if(tab == 'pending'){
return [4, "desc"]; // sort publication date column
} else {
return [5, "desc"]; // sort closing date column
}
}
Thank you!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use the
order()
API insideinitComplete
to set the order based on the conditions.Kevin
@kthorngren
Thank you Kevin
I added table.order([4, 'asc']).draw(); inside initComplete as you said ant it worked.