views:

1419

answers:

3

i have a column with buttons in a table an i am using jwuery 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.

+1  A: 

from this page:

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

    //...
} );
cobbal
but i am clicking on a button inside a table cell
ooo
+1  A: 

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(); 
}
Sridhar
this doesn't seem to work ..
ooo
+3  A: 

Hmm. Try this:

var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
Jason Orendorff
+1 but I think closest would be a more appropriate selector than parents
cobbal
i did switch it closest but after that it worked perfectly .. thanks
ooo