Reputation: 4323
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?
Upvotes: 8
Views: 20239
Reputation: 1
If anyone reading is interested in achieving the same table behavior without JQuery ('table' is your Datatable object variable):
table.rows('.selected').deselect()
This one line deselects all the selected rows in every page.
Upvotes: 0
Reputation: 41
This is not mine. Found it on the Internet. But it works like a charm:
var table = $('#myTable').DataTable();
table.rows().deselect();
Upvotes: 2
Reputation: 163
.deselect()
or
table = $("#main_index1").DataTable();
table
.rows( '.selected' )
.nodes()
.to$()
.removeClass( 'selected' ); did not work for me.
I did the following change and it worked. I had to explicitly set the checked property to false.
var rows = table.rows({ page: 'current' }).nodes();
$('input[type="checkbox"]', rows).prop('checked', false);
Upvotes: 0
Reputation: 189
You can achieve this via Tabletools.js plugin
Get the tabletool instance of the actual table:
var oTT = TableTools.fnGetInstance('file-records');
oTT now supports various methods for datatable:
oTT.fnSelectNone();
fnSelectNone()
deselects all rows (previously selected) across every page
Upvotes: -2
Reputation: 4323
Figured this out...tried this instead:
table = $("#main_index1").DataTable();
table
.rows( '.selected' )
.nodes()
.to$()
.removeClass( 'selected' );
Worked like a charm.
Upvotes: 14