How to make order() return multiple ordering columns
How to make order() return multiple ordering columns
According to manual: https://datatables.net/reference/option/order ,
"function returns array of arrays containing information about the currently applied sort. This 2D array is the same format as the array used for setting the order to apply to the table (see below)".
When using "orderData" option to set multiple columns sorting, order() function still returns only one element in array.
You may try to execute this code on the page, example of use orderData option ( https://datatables.net/examples/basic_init/multi_col_sort.html ):
$("#example").DataTable().order();
If you didn't change the order of columns, the result would be:
[[0, "asc"]]
,
but according to "orderData" option result should be:
[[0, "asc"], [1, "asc"]]
This question has an accepted answers - jump to answer
Answers
After closer look, I found that order() returns "aaSorting" property, which is a "Sorting that is applied to the table" value, but it doesn't include "orderData" columns, which are included to the sorting rules on every sorting event by function "_fnSortFlatten". This function returns extended multi-dimension array with next fields:
1 col
2 dir
3 formatter
4 index
5 src
6 type
In my case I need only "col" and "dir" fields, so to get return value in same format as API order() function, it is easy to implement the next new API function:
I could miss the other way to solve this problem, so it would be great if someone share with me the other (true) way :)
Yup - perhaps the built in API should be extended to be able to get the full ordering array. I'll look into that - thanks for the suggestion.
Allan