Skip to content
Advertisement

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?

Advertisement

Answer

Figured this out…tried this instead:

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

Worked like a charm.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement