Reading _DT_RowIndex Property
Reading _DT_RowIndex Property
Lucid
Posts: 7Questions: 3Answers: 0
I'd like to be able to read the _DT_RowIndex property to quickly get the row index, but I can't seem to figure out how to get to it. For example, if I do the following, I can see the property for the object in the console, and I know it's the one I want. I just can't figure out how to read it so I can stash it in a variable.
$desiredRow = $clickedButtonIntheRow.closest('tr').off('click');
console.log($desiredRow);
var test = $desiredRow._DT_RowIndex;
console.log(test);
Can anyone point me in the right direction?
Thanks!
This discussion has been closed.
Answers
That's not working because your
$desiredRow
variable is a jQuery object, while the property is added to the node itself. Using$desiredRow[0]._DT_RowIndex
would work in the above case.BUT Don't do that!!!
The leading underscore indicates that it is a private property. Use
row().index()
instead since that is the documented method for getting this information and it won't change. The private property might.Allan
Thanks for the reply! Understood about staying away from that property.
Maybe you, or someone else, can shed some light on things and give me a nudge in the right direction...
I've got a DataTable that uses pagination. So if a user is on page 3, and clicks the 4th row, some of the cells in that row become editable. But if the user clicks a Cancel button, they revert back to their original state.
Currently I was using something like this to loop through and reset the editable cells:
But that seemed to go weird and pull the wrong cell.data() if I'm on page 3, row 4, and not page 1, row 4.
Am I missing something obvious? Thanks!
Well, it never fails. You go hunting and researching and can't find your answer. You post on the forum, and then poke around for 5 minutes more and stumble across it.
I started thinking more about what was going wrong, and the way I was grabbing the row index was slightly off. After looking at this example I tweaked my code and think I'm rolling now:
https://datatables.net/examples/ajax/null_data_source.html
Thanks for nudging me in the right direction!
No problem - good to hear I was able to be of some help .
Allan