Reputation: 1581
i've built up a table with dataTable jQuery plugin. I am trying to get the td data of a tr element by clicking on that tr. I've read the documentation which says that i have to use "fnGetData", but when i try that, i get the error:
TypeError: table.fnGetData is not a function
var data = table.fnGetData( this );
My js Code:
$('#customerTable tbody').on('click','tr', function(){
var data = table.fnGetData( this );
alert(data);
});
My DataTable is initialized as the following, working well without the click event:
var table = $('#customerTable').DataTable( {..});
Do I have to bind another plugin script in my html head section?
Regards.
Upvotes: 4
Views: 5817
Reputation: 7518
It seems there is a difference in the API datatables provides whether you initialize it with DataTable({..})
vs dataTable({..})
. The differences can be seen here.
Since you initialized it with the newer API you should instead in your listener use.
var data = table.row( this.rowIndex-1 ).data();
If you used dataTable({..})
to initialize your table the code that you posted should work.
Upvotes: 4