Get DataTable object from cell click event
Get DataTable object from cell click event
mctrivia
Posts: 1Questions: 0Answers: 0
I have multiple tables on the same page. I would like to have an onclick event for multiple cells based on class. This part is easy. What I can't seem to figure out is how to get the DataTable object associated with the clicked cell.
Any ideas.
Replies
This example uses
cell().data()
to get the data of the clicked cell:http://live.datatables.net/retoniyi/1/edit
If you still need help please provide a simple test case showing what you are trying to do.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I am using the above
cell().data()
. It works perfect!Is there a possibility to click on a cell and getting instead the data from a cell in the same row, several colums left or right?
Thanks for any help!
Yep, you can just get the entire row data with
```
table.row(this).data()
````
as that also accepts a
td
,Colin
Hi Colin,
thanks for your quick reply! I allready tried
table.row(this).data();
But it returns undefined.table.cell( this ).data()
returns the correct value. In the last column I have an icon. I am looking for a way, to click on the last cell in the row (icon) and get the data from the first cell of the row for further calculations.This is what I tried:
Is there no way to get a specific cell of the row by clicking on another cell in the row? Instead of
this
cell, the cell two colums left?Thanks Harald
The
row-selector
docs state that using thetd
for row selection was put in Datatables version 1.10.11. Are you using an earlier version?Your code works in this test case with the latest version:
http://live.datatables.net/zecacima/1/edit
You can use jQuery closest() to get the closest
tr
, like this:Kevin
Hi Kevin,
thanks for your reply. Starting to update to latest version and give it another try!