Row index in a custom sort function
Row index in a custom sort function

For a custom sort I need to access parts of the sorted row data other than the compared values. So I would want to access the row data by table.row( index ).data();
However, I would need a row index for that and the function only provides the values to compare.
This is the code:
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
'grouped-asc': function(a, b) {
var thisData = tabletool.table.row(idx).data();
// ...
return a < b ? -1 : a > b ? 1 : 0;
},
'grouped-desc': function(a, b) {
var thisData = tabletool.table.row(idx).data();
// ...
return a < b ? 1 : a > b ? -1 : 0;
}
});
How can I include the row index in this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @gSibinger ,
That's not possible with the sorting extensions. As you say, you're only comparing single values and there's no way of mapping that back onto the original row.
There are two other options that may be relevant. First, you can use
columns.orderData
to use values of another column when ordering. Also, orthogonal data can be used to change the value of the data used for sorting, seecolumns.render
. This would have the information for the entire row so can be considered.Cheers,
Coln
Hi Colin,
I was able to use columns.render to send an object containing all necessary information to the sort function. Thanks for your help!
Regards
Georg