Row re-ordering in API not working as expected

Row re-ordering in API not working as expected

sronsieksronsiek Posts: 52Questions: 11Answers: 0

DT: 1.11.5

I have a DT with column sorting. Via user selections (not using sorter extension), I have an array of selected row IDs (ie internal DT row IDs), which I now wish to re-order based on the current table order settings, before passing data from the rows to a server request.

From the documentation this is exactly what the order modifier in combination with rows() is for:

The order modifier provides the ability to control which order the rows are processed in. This can have an effect on the return from chained functions ...

Hence I expect this construct to do what I want:

table.rows( <array of row IDs>, {order:'current'}).every( function ( rowIdx ) { ... collect the data ... })

However I'm not seeing any re-ordering, the output from the following always reflects the order of the row ID array, even though there are sorted columns in the table:

oTable.rows( [2,0,1], {order:'current'} ).every( function ( rowIdx ) { console.log("rowIdx: " + rowIdx); } )
VM13225:1 rowIdx: 2
VM13225:1 rowIdx: 0
VM13225:1 rowIdx: 1
_Api [Array(3), context: Array(1), selector: {…}, tables: ƒ, table: ƒ, draw: ƒ, …]

Reversing the array should give me a differnt order:

oTable.rows( [1,0,2], {order:'current'} ).every( function ( rowIdx ) { console.log("rowIdx: " + rowIdx); } )
VM13278:1 rowIdx: 1
VM13278:1 rowIdx: 0
VM13278:1 rowIdx: 2
_Api [Array(3), context: Array(1), selector: {…}, tables: ƒ, table: ƒ, draw: ƒ, …] 

Note I'm not able to use the DOM (eg to tag rows using a css class) as I'm using DT sorter, where only a portion of the table is in the DOM.

It feels like I'm doing something basic wrong?

Sign In or Register to comment.