How to loop over rows/columns in display order?

How to loop over rows/columns in display order?

bflbfl 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!

Answers

  • colincolin Posts: 15,176Questions: 1Answers: 2,589

    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

  • bflbfl Posts: 26Questions: 7Answers: 1

    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.

  • bflbfl Posts: 26Questions: 7Answers: 1

    note that I'm using 2 fixed columns as well

  • bflbfl Posts: 26Questions: 7Answers: 1

    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

  • bflbfl Posts: 26Questions: 7Answers: 1

    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

  • kthorngrenkthorngren Posts: 20,420Questions: 26Answers: 4,794

    Maybe you can update Colin's example with what you are doing so we can help diagnose.

    Kevin

  • colincolin Posts: 15,176Questions: 1Answers: 2,589

    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

  • bflbfl Posts: 26Questions: 7Answers: 1

    @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

This discussion has been closed.