Getting the row api to work
Getting the row api to work
Hi everyone,
I am having a tough time getting the datatables.js api working. Specifically, I am working with a datatable and I would like to get the <td> nodes of a row. To do this, I have the following code in an onclick event handler:
$("#IndustrySummary").on("click", "a", function (evt) {
evt.preventDefault();
var table = $('#IndustrySummary').DataTable();
**var rowIdx = table.row(this).index().row; ** //This line throws an error
var tds = table.rows(rowIdx).nodes();
var tds2 = $(this).parent().siblings();
alert("clicked!")
})
which I copied from this link:
https://datatables.net/reference/api/cell().index()
The chained statement shown in bold face throws the following error:
SCRIPT5007: Unable to get property 'row' of undefined or null reference
Here is the basic structure of my table (actual names changed for security purposes)
$('#IndustrySummary').DataTable({
data: data.SPVIndustryInfoesSummary,
columnDefs: [
{ title: 'One', targets: [4] },
{ title: 'Two', targets: [5] },
{ title: 'Three', targets: [6] },
{ title: 'Four', targets: [7] },
{ title: 'Count', targets: [8] },
{ visible: false, targets: [1, 2] },
],
columns: [
{ data: "One" },
{ data: "Two" },
{ data: "Three" },
{ data: "Four" },
{ data: "Five" },
{ data: "Six" },
{ data: "Seven" },
{ data: "Eight" },
{ data: "Count" },
{ data: null, defaultContent: '<a href="">View</a>' }
],
})
Any advice would be helpful. Thank you for your time and assistance!
Answers
You have this:
But the example in the doc you linked to has this:
The difference is the
row().index()
will return the row ID as an integer so you don't want the.row
at the end. Wherecell().index()
returns an object which one of the properties isrow
. The.row
at the end of the chain returns the value (row index) of therow
property.Kevin