I'm using dataTable plugin to show data from Database , The table looks like:
name location actions
jack New York Edit , Delete
john London Edit , Delete
... ... Edit , Delete
The Adding/Editing/Deleting functions are working well , But I have to refresh the page to see the results.
How to reload the table but keep the previous parameters like page and searching if they exist?
I'm using dataTable plugin to show data from Database , The table looks like:
name location actions
jack New York Edit , Delete
john London Edit , Delete
... ... Edit , Delete
The Adding/Editing/Deleting functions are working well , But I have to refresh the page to see the results.
How to reload the table but keep the previous parameters like page and searching if they exist?
Share Improve this question asked Mar 9, 2018 at 22:10 jackjack 1512 silver badges12 bronze badges2 Answers
Reset to default 3You can use:
table.ajax.reload(null, false);
The second parameter is resetPaging, if is true will reset the datatable to default, if is false will hold the current paging position. The first parameter is a callback function.
For more information, see: https://datatables/reference/api/ajax.reload()
If using and XHR data source with DataTables:
// Init DataTables with XHR source
var table = $('#myTable').DataTable({
ajax: "my/xhr/data/source"
});
// Reload the table every 30 seconds
setInterval( function () {
table.ajax.reload();
}, 30000);
Of course, you could reload under a refresh button on after you add/edit/delete rows in your XHR callbacks.