Having issues with getting id from clickable row
Having issues with getting id from clickable row
nabberuk
Posts: 1Questions: 1Answers: 0
I'm trying to get the ID (hidden column) when clicking on a row. Here's what i have that works but displays the first name and not the hidden column (ID)
I've uploaded the html/js here > http://live.datatables.net/pidijika/1/
It's using server side processing so won't display correctly on live.datatables.net
This discussion has been closed.
Answers
There are a few different ways to go about it. One way is on the server-side you can use DT_RowId in your query, and whatever you put in that will be the ID of the row. In this case if that is the only ID you care about for each row, it would make sense to do that.
As far as I can tell,
row().data()
seen here does not show the hidden cells, otherwise that would be an easy way.The easiest way would probably be to just do this though, adding in
fnCreatedRow
and assign an attribute to eachtr
using the data of your hidden column. In this example, thedata:"id"
is your hidden column and has the data you want.as ignignokt said, there are a couple of ways to do it.
My preferred method is a little different.
to make a table have select-able rows, i have an event handlers bound to the td elements of the table, and add a .selected class to the tr element (can use this to make it visibly selected as well).
defining your columns is a good way to know what the data variable will be defined as.
i also use the row function which accepts a tr element. for example