How to loop over rows/columns in display order?
How to loop over rows/columns in display order?
bfl
Posts: 26Questions: 7Answers: 1
This is likely trivial, but I'm not having luck with cells.every(), which seems to return row indexes unrelated to display order.
I just want to loop over the cells of the table by row and then column, as currently displayed based on sort, etc.
So (1,1), (1,2)..., (2,1), (2,2)...
thanks!
This discussion has been closed.
Answers
Hi @bfl ,
cells().every()
does what you're after. If you look at the example here, you can see when you click the button it always displays the cells in the order you wanted.Cheers,
Colin
thanks @colin ! - I'm still seeing it return rows out of order with my little loop, looking at the rowIndex passed to the callback for the "every" method.
note that I'm using 2 fixed columns as well
also -
I'm first adding rows to the table dynamically, and there is a default sort order it seems to nicely adhere to as the rows are added
while the rowIndexes are out of order, the row indexes are consistent when I repeat things
shoot - I resorted to using dt.cell({row:rowIndex, column: columnIndex}) and the "rowIndex" does not seem to correspond to the currently displayed row order either
Maybe you can update Colin's example with what you are doing so we can help diagnose.
Kevin
Yep, as Kevin said, please update the example with what you're seeing, and explain why you think that's wrong. One thing to note, is that the rowIndex is the order that the data is loaded, not what you see on the screen - a row will keep the same index regardless of the sort order being implemented.
C
@colin
ok - found an old answer Allan gave that helped
internalRowNumber = table.rows( { order: 'applied' } )[0][displayedRowNumber]
there's probably an api/easier way to do it - I just inspected the rows object to see where the values were