How to get access to the row's data from the DataTables select event?

How to get access to the row's data from the DataTables select event?

TomBajzekTomBajzek Posts: 115Questions: 25Answers: 1

I have a handler for the DataTables select event. In that handler I need to examine and possibly change the class of one of the td elements in the selected row. I know that I can use row = dt.row(indexes) to use that row within DataTables. In this case, row is a reference to an _Api array, not a jquery object that I can manipulate. I've tried several things, but I have not figured out how to access the individual td elements, etc. in that row.

I've not found the answer to this in the documentation or forums. Some advice would be most helpful.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 6,090Questions: 21Answers: 1,347
    Answer ✓

    row().node() will give you the tr for the row. You can also use cell().node() to get a specific cell's td. The to$() will allow you to get a jQuery object from the API. You can combine the examples in the select event to achieve the result you want. Here is an example:

    http://live.datatables.net/nusisije/1/edit

    Kevin

  • TomBajzekTomBajzek Posts: 115Questions: 25Answers: 1

    Kevin,

    Thanks for this answer. I'd been aware that these functions existed, but I hadn't realized that they were what I needed. The example was especially helpful as I'd not visualized how these were to be used when I'd read about them previously.

    I think it might help others if the documentation had a link to the example you referred to. That might save someone else some time and puzzlement.

    This part of the project is now nearly complete.

    Thanks very much,
    Tom

Sign In or Register to comment.