how to remove a row from a DT rendered via Ajax
how to remove a row from a DT rendered via Ajax
I'm using the DataTables inside the jQuery UI Tabs. More importantly, my content is fetched via Ajax. I am able to fetch and display the data exactly how I want it. The problem I'm having is I can't seem to remove rows using fnDeleteRow() method. My entire table (id="my_table") content is brought back via AJAX and therefore my DataTables init method is dynamically bound via the live query plugin. When I run my code (see below) I get a really strange error saying "Cannot read property '_aData' of undefined" at line #126 in jQuery.dataTables.min.js. My guess is that I can't just save the dynamically created instance of my DataTables object into a variable and use that variable to delete an existing row but I'm not 100% sure. When I run the code using a static HTML markup, everything works great. In this case, how would I remove rows? Any insight/assistance would be greatly appreciated!
My HTML code looks something like this:
.....
...
...
My JS code looks like as follows:
var oTable;
$('my_table').livequery(function() {
oTable = $(this).dataTable({
/* dataTable init code goes here */
});
});
$('#button_image_137').livequery('click', function(event) {
/* Make a AJAX call to a server-side PHP script to remove the record with primary key = 137 */
var pos = oTable.fnGetPosition($('#tr_137'));
oTable.fnDeleteRow(pos);
});
My HTML code looks something like this:
.....
...
...
My JS code looks like as follows:
var oTable;
$('my_table').livequery(function() {
oTable = $(this).dataTable({
/* dataTable init code goes here */
});
});
$('#button_image_137').livequery('click', function(event) {
/* Make a AJAX call to a server-side PHP script to remove the record with primary key = 137 */
var pos = oTable.fnGetPosition($('#tr_137'));
oTable.fnDeleteRow(pos);
});
This discussion has been closed.
Replies
Also you can change this:
[code]
var pos = oTable.fnGetPosition($('#tr_137'));
oTable.fnDeleteRow(pos);
[/code]
to
[code]
oTable.fnDeleteRow( $('#tr_137')[0] );
[/code]
Allan