I am using Datatables jQuery plugin to display data. Here is what I need:
- When the user gives input to the search box the pagination goes away and shows all the records at once.
- When the user clears the search box the table should go back to its original state with the pagination, etc.
Is there a way to do this? I've tried doing the following:
var $dt = $('#datatable').DataTable();
$("input[type=search]").keyup(function() {
var search_string = $(this).val();
if(search_string.length > 0) {
$dt.destroy();
$('#datatable').DataTable({
"paging": false
});
} else {
$('#datatable').DataTable();
}
});
But after I start typing, the Datatable reloads and the cursor is not inside the search box.
.destroy()on the table when you search, with new options, and then put back the original options when you remove the search?destroy()first? Just set pagination to false?$('#datatable').DataTable().destroy();line, and test?