Avatar of WestCoast_BC
WestCoast_BC
Flag 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

HTMLColdFusion Language* jqueryDatatablejQuery

Avatar of undefined
Last Comment
WestCoast_BC

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lenamtl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck