How to select a row by its (displayed) index in an ordered DataTable ?
How to select a row by its (displayed) index in an ordered DataTable ?
Hello,
I want to be able to select a row in my dataTable using keyboard's arrows (or any other way).
I've an index var (let's call it myCursor) going from 0 to DT.page.info().recordsTotal - 1
. When i press a key, it updates MyCursor, changes page if needed and now, i want to add a class to the row having myCursor as index.
i wrote
DT.row(myCursor).nodes().to$().addClass("myClass");
However, as the table is sorted, myCursor does not correspond to the displayed element.
How should i do to get the displayed row corresponding to myCursor ?
Thx in advance
This question has an accepted answers - jump to answer
Answers
There is no
row().nodes()
method - eitherrows().nodes()
orrow().node()
. The above code should be giving an error on the browser's console I would think.Beyond that, if you could link to the page that would be useful.
Allan
There's no page avaible yet, but i'm positive, there's no error with that code (Firefox + Firebug).
the switch(event.keyCode) code is
And except for the highligthning order, it works pretty fine...
May i asked how you would get the next/prev item ?
Thank you vm.
I must confess I don't know why that isn't giving an error. It should! I would very much recommend you use either
row().node()
.As to why it isn't working - I'm not sure! It is operating on the DataTables internal row index. You probably want to pass
{page:'current'}
into therow()
selector.Allan
Ummm looks like we're misunderstanding... Maybe my english is a bit bad :/
for row.node, on
row().node()
, there's :Isn't it what i did ?
For my main question, I made a very simple page from my code to explain :
The point and is that i can't get the index working. When i press key UP, the highlighting order is going wrong.
Thx again and sorry for being annoying.
Yes - that is what you have done. The example is wrong. Fixed committed and I'll push it up to the site soon. Thank your for letting me know about that.
For for why your example isn't working -
myCursor
is an integer, which means thatrow()
is selected on the row data index (see therow-selector
documentation). If you want it to select based on current position use':eq('+myCursor+')'
to use a jQuery selector.Allan
It works !
I never though the row data index would'nt be an integer.
Thank you very much !