Get DataTables element

Get DataTables element

rolandowrolandow Posts: 2Questions: 1Answers: 0

I wrote my own little jQuery module that handles action buttons on a table. When I delete a row, I would like to test if the table is a datatable, and then remove the row through the DataTables api.

This returns true: $.fn.DataTable.isDataTable( $(that).closest('table.table-clickable')

But this doesn't work:

if ($.fn.DataTable.isDataTable( $(that).closest('table.table-clickable') )) {
  console.log('table seems to be a datatables');

  var myTable = $(that).closest('table.table-clickable').DataTable();
  myTable.row($(that).closest('tr')).remove.draw(false);
}

It gives me "TypeError: myTable.row(...).remove.draw is not a function"

What am I missing?

Answers

  • rolandowrolandow Posts: 2Questions: 1Answers: 0
    edited December 2014

    Nevermind. As usual I seem to be able to answer my own question after asking for help :-s

    This seems to be the solution:

    if ($.fn.DataTable.isDataTable( $(that).closest('table.table-clickable') )) {
        var myTable = $(that).closest('table.table-clickable').dataTable().api();
        myTable.row($(that).closest('tr')).remove().draw(false);
    }
    
This discussion has been closed.