cell().index().row not returning current row index regardless of order modifier
cell().index().row not returning current row index regardless of order modifier
When using the cell() selector to select a single cell, the row index is always the initial index. This seems to be the case with either the default selector-modifier or explicitly setting the order to current.
In this bin, Hope Fuentes is initially on row 37 but after the sort done in the table initialization, Hope Fuentes is on row 13. Index is always returned as 37 and not 13.
Seems like a bug.
data tables live jsbin
http://live.datatables.net/saweyado/1/edit
debugger output
http://debug.datatables.net/ejixew
edit:
This row index is also inaccurate if .index().row is chained to the original cell() method.
This question has accepted answers - jump to:
Answers
The index will always start at 0 (or 1?) for the first row, then increment down, regardless of the order, if you want to use something that wont do that, I recommend using the
rowId
hi jLinux, not sure I get you. This is not an off by 1 type of thing. I want to know the current row index, after sorting has been done on the table, rather than the initial row index.
Thats what im saying. Sorting the row will change the indexes, as they will always increment from the top down, no matter how many times you order columns
This is correct and intentional. If you want to use the current index, use
:eq(0)
to select the first row.Allan
Oh, then maybe I was wrong.. Sorry. I use
rowId
for this reasonYes, using a DOM ID removes the positional issue entirely.
Allan
Which is what I definitely recommend! You can use
row().id()
androws().ids()
Thanks guys. I'm not sure how row().id or using :eq(0) to select by row index helps me out. I guess it is faster to select a row by an id, or the :eq(0) selector. That is not my problem though. I am selecting the row already in the bin i linked to. Figuring out where the row is in the table after selected is still a problem for me. If my cell was always displayed on the page when I need to know its row, there would be no problem, but the chance is more likely that is paged. Maybe I am missing something in the row().id() spec, seems like it gives a way to select a row; not sure how to figure out current index once selected though. Maybe my initial post was vague, I figured the jsbin would make it more clear. Maybe I am missing something fundamental.
Thanks for clearing up my misunderstanding of cell().index().row though. I appreciate the hand.
Also, I guess this works to get current row index using initial row index:
changes to bin below:
http://live.datatables.net/saweyado/2/edit
thanks again guys.
I see - you want to find the row's position in the table - in which case, indexOf`, as you have done is probably the best way of doing it.
Allan