Link to home
Start Free TrialLog in
Avatar of WestCoast_BC
WestCoast_BCFlag for Canada

asked on

how to clear selections in datatable

I am using datatables (https://datatables.net/). My tables contain a column with checkboxes. I get which rows are checked by doing the following: 

    var tu = $('#mytable').dataTable().api();
    var rows_selected = tu.column(0).checkboxes.selected();

Open in new window


This works fine until I recreate the table with new data. When I execute the code above I am getting the selected rows from the initial data. I have tried calling destroy() and clear() before I call datatable() again.  Ie, I have tried doing:

$('#mytable').DataTable().clear().destroy().draw();

Open in new window


I am recreating the table by doing the following:

$("#contactlist").html(data);

Open in new window


where data contains the html for the table (ie <table><thead> ....</thead><tbody>....</tbody></table>)


Can anyone help me figure out what I need to do to clear the previously selected rows.

Thank you

ASKER CERTIFIED SOLUTION
Avatar of lenamtl
lenamtl
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WestCoast_BC

ASKER

Thank you. Yes, I was using stateSave and that was causing my problem. I am already using the checkbox plugin and setting stateSave for the checkbox column has solved my problem