sort by difference with group in rowGroup
sort by difference with group in rowGroup
wintermelon_lover
Posts: 6Questions: 5Answers: 0
in General
Link to test case: http://live.datatables.net/bulidolu/3/edit
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
When I group data in datatables, I will group them in pairs or leave one data in a group. Is there a way to sort data so that for group with 2 rows, those with large difference cone first, and group with 2 rows come before group with 1 row? Thanks!
Answers
columns.orderData
is the option you want here I think. It can tell DataTables to use multi-column sorting for a column: http://live.datatables.net/bulidolu/4/edit .Allan
Thanks for reply! It seems orderdata only consider index. Is there anyway to make it also consider difference within group?
For instance, in the example, in group a the absolute difference is 20, in group b the absolute difference is 50, in group 3 there is only 1 record. Then the order need to be b -> a -> c. Is there a way to achieve that?
One way is to calculate the differences in
initComplete
, update a hidden column with the difference for each group then calldraw()
to update the table sorting. See this example:http://live.datatables.net/bulidolu/5/edit
It uses the following API's:
column().data()
rows().data()
with therow-selector
as a functionpluck()
toArray()
There might be more efficient ways to do this. You can hide the
diff
column withcolumns.visible
Instead of doing all this at the client you could get the difference each group at the server then place the difference in each row for the group.
Kevin