How to delete current row with jquery datatable plugin

Viewed 40694

I have a column with buttons in a table I'm using jQuery datatable plugin. The buttons say "Remove" and the idea is that when you click on that button it deletes the current row in the table.

When I call fnDeleteRow it seems to work the first time but no any further time for that row so it looks like its not really deleting the row properly.

5 Answers

Try this:

var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));

If it doesn't work, check the following example

Let's say you attached a function to be called when the user clicks on the button. The function would be something like this

function DeleteRow(event)
{
  //get the row of the cell that is clicked
  var $row = $(this).parents("tr").eq(0)
  //if you need the id you can get it as
  var rowid = $row.attr("id");
  //now you can call delete function on this row
  $row.delete(); 
}

from this page:

$('#example tbody td').click( function () {
    /* Get the position of the current data from the node */
    var aPos = oTable.fnGetPosition( this );

    //...
} );
Related