Reputation: 9823
Taking a cue from Generated Content for a Column, I used the same code to add a 'Delete' option as an extra column in my returned data. The 'Delete' option is showing up in the table, but when I click on it, I'm getting
t.row is not a function
error. Below is the code that I'm using:
var t = $("table#available_profiles").dataTable({
"processing": true,
"serverSide": true,
"ajax": "retrieve_profiles",
"columns": [
{ data: 0 },
{ data: 1 },
{ data: 2 },
{ data: 3 },
{ data: 4 },
{ data: 5 },
{ data: 6 },
{
data: null,
defaultContent: '<a href="#" class="remove">DELETE</a>',
orderable: false
},
],
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
} ],
"order": [[ 5, "desc" ]]
});
$('table#available_profiles').on( 'click', 'a.remove', function () {
var data = t.row( $(this).parents('tr') ).data(); // error here
alert( data[1] +"'s salary is: "+ data[ 7 ] );
return false;
} );
The table is getting drawn with the data processed from server side. So there are no missing js files or syntax errors with either the plugin js or the server side code.
From what I can tell, t
is a global variable too. So it should be available inside the a.remove
click function. But I'm running out of ideas on why this isn't working.
Doing
console.log(t);
is returning the following:
And I don't find the row()
function anywhere. How could this be possible?
Upvotes: 1
Views: 450
Reputation: 9823
Ok. I solved it. The problem was I was calling the plugin as
$("table#available_profiles").dataTable({....});
whereas it should have been
$("table#available_profiles").DataTable({...}); // notice the capital D
Upvotes: 2