Reputation: 1274
Have some data, whick comes from AJAX and is rendered in table. Also have toggle button, its phases are 'Show duplicates' and 'Show all'. When come to page first time, all data is rendered, button phase is 'Show duplicates'. If press 'Show duplicates', special ajax request goes to server, and response is processsing in JS:
if (res[0] == '200' || res[0] == '404') {
if (!is_duplicates_showed) { //if pressed 'Show duplicates'
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
return $.inArray($(table.row(dataIndex).node()).find('td:first').find('form').find('input[name="registration_id"]').val(), res[1]) > -1;
}
);
table.draw();
} else { //if pressed 'Show all'
Result: only those rows are visible, which registration id
appropriates to such ids from ajax. Button phase changes to 'Show all'.
Question: how to reset data (show all data again), when press 'Show all'?
What I tried (in else
section):
1.
var table = $('#participants').DataTable();
table
.search( '' )
.columns().search( '' )
.draw();
2.
$.fn.dataTable.ext.search.pop();
3.
table.destroy();
var newTable = $('#participants').DataTable();
newTable.draw();
No success. After these operations I still see "filtered" rows, which were given by push()
result.
Upvotes: 2
Views: 9292
Reputation: 58860
Try the code below:
$.fn.dataTable.ext.search = [];
table.draw();
Upvotes: 2