access row data
access row data

If I have something like:
table.on( 'select', function ( e, dt, type, indexes ) {
if ( type === 'row' ) {
blah, blah
}
} );
how can I access the values of the data on the row that was selected?
I tried:
table.row(this).data()
but it comes undefined. Not sure why.
This question has accepted answers - jump to:
Answers
Depending on your configuration more than one row can be selected. The
indexes
parameter contains an array of indexes of the selected items. See the examples in theselect
event docs to learn how to access the selected rows. In addition take a look at these examples:https://datatables.net/extensions/select/examples/api/get.html
https://datatables.net/extensions/select/examples/api/events.html
Kevin
Thank you Kevin. I figured a way of making this work and access the values via table.cell(index,column).
I guess, my question remains, more like rhetorical: why table.row(this).data() is null in table.on('select'....
Just a curiosity
Thank you Kevin. I figured a way of making this work and access the values via table.cell(index,column).
I guess, my question remains, more like rhetorical: why table.row(this).data() is null in table.on('select'....
Just a curiosity
Go to this example and paste the following code into the console:
You will see
this
is the table. This makes sense as one element can be selected, multiple elements can be selected and there is theselect()
API.Kevin
Yup, in DataTables
this
is thetable
element (I do wish it was the API, but that's a legacy thing...). It is not the table row, which it sounds like you were expecting @aziegler3.The
indexes
parameter passed in gives you the data indexes of the row(s) that were selected, so you can do:Allan
Thank you guys. This is helpful to understand. I like to understand how things work.