Delete row using jQuery Datatable Plugin by id

oTable strings have unique identifiers.

Why is this code not working?

 oTable.fnDeleteRow( oTable.fnGetPosition( $('#row'+id+'-tr'))); 

error:

 [18:10:44.631] nNode.nodeName is undefined @ http://localhost: ... /jquery.dataTables.js:1903 

Thanks!

change

Example:

 <table> <thead> <th> <td>Name </td> <td>Delete</td> </th> </thead> <tbody> <tr id="row0-tr"> <td> Row 0 </td> <td> <Button onclick="deleteRow(0)"> - </td> </tr> <tr id="row1-tr"> <td> Row 1 </td> <td> <Button onclick="deleteRow(1)"> - </td> </tr> <tr id="row2-tr"> <td> Row 2 </td> <td> <Button onclick="deleteRow(2)"> - </td> </tr> </tbody> </table> 

change 2:

The real problem: how to get table row using id ?

The fnGetPosition($('#row'+id+'-tr') method does not return a string.

I put this code before calling fngetPosition: console.log($('#row'+id+'-tr')) and returns: ({length:1, 0:({}), context:({}), selector:"#row1-tr"})

Thanks for the help!

+4
source share
2 answers

Answer:

 oTable.fnDeleteRow( oTable.fnGetPosition( document.getElementById('#row'+id+'-tr'))); 
+4
source

Looking at the source code of jquery.dataTables on line 1903, it seems to me that $('#row'+id+'-tr') returns an empty object in your case. This means that the selector does not exist on your page.

You can verify this by putting console.log($('#row'+id+'-tr')) before oTable.fnDeleteRow(

0
source

All Articles