fnDeleteRow with jQuery

fnDeleteRow with jQuery

mbstefmbstef Posts: 7Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
Into the last cell on a table with datatables i use icons for some actions. One of them are a delete-icon, with this the data into this row will delete with ajax. Now i'd like to delete the row also from datatable and i try it to do so:
[code]var row = $(this).closest('tr');
$('.dataTable').dataTable().fnDeleteRow(row);[/code]

But this will delete the wrong row into the table. The datatable object will create in another function and i don't have it globally.
How can i delete the correct row?

Thanks,
Stefan

Replies

  • hozthozt Posts: 45Questions: 0Answers: 0
    That's weird, I have the same exact code on my project and it works.
  • hozthozt Posts: 45Questions: 0Answers: 0
    edited April 2012
    Well, truthfully I do this:

    [code]
    var id_row = $(this).closest('tr').attr('id');
    var nRow = $('#myTable tbody tr[id='+id_row+']')[0];
    oTable.fnDeleteRow( nRow, null, true );
    [/code]

    Assumptions for you:
    1. oTable is var oTable = datatable.. etc
    2. #myTable is table's id
    3. And the reason i can do tr[id= is because I load my data with a DT_RowId field for each row, which DatatTables associates with the tr's.
  • mbstefmbstef Posts: 7Questions: 0Answers: 0
    That's it! I use everytime the jQuery-Object not the node. With this
    [code]var row = $(this).closest('tr');
    var nRow = row[0];
    $('.dataTable').dataTable().fnDeleteRow(nRow);[/code]

    will it work correctly.

    Thanks hozt ;)
  • walreyeswalreyes Posts: 1Questions: 0Answers: 0

    Wow, thanks a lot.

    I was struggling with the same problem and this totally solved it.

  • gladsonreisgladsonreis Posts: 12Questions: 0Answers: 0

    Perfect !

  • mainakibuimainakibui Posts: 1Questions: 0Answers: 0

    I use

    $('#editable').dataTable().fnDeleteRow('#table-row-'+row_id);

  • fallphenixfallphenix Posts: 2Questions: 0Answers: 0

    Very good my brother:

         nRow = $("#"+idindex+'q').parent().parent()[0];
    
           table = $('#tabIn').dataTable();
           table.fnDeleteRow( nRow, null, true ); 
    

    and it work well

This discussion has been closed.