Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deselect all selected rows in DataTables

I'm using jQuery Datatables plugin (v 1.10)

I am using the select feature and can highlight/select rows fine. I'm also using paging. I can page through the tables and select on multiple pages. I tried to create a button to clear selected rows, but it only clears rows selected on the current page.

Like this: $('#main_index1 tbody tr').removeClass('selected');

For example, if I have a row selected on page 1 and then go to page 2 of the table and run this function, the row selected on page 1 isn't deselected. If I selected something on page 2, that deselects just fine.

Any ideas how to deselect all selected rows across all pages?

like image 275
jonmrich Avatar asked Feb 10 '16 16:02

jonmrich


1 Answers

Figured this out...tried this instead:

table = $("#main_index1").DataTable();
table 
    .rows( '.selected' )
    .nodes()
    .to$() 
    .removeClass( 'selected' );

Worked like a charm.

like image 75
jonmrich Avatar answered Sep 30 '22 14:09

jonmrich