ajax.reload()
Reload the table data from the Ajax data source.
Description
In an environment where the data shown in the table can be updated at the server-side, it is often useful to be able to reload the table, showing the latest data. This method provides exactly that ability, making an Ajax request to the already defined URL (use ajax.url()
if you need to alter the URL).
Type
function ajax.reload( callback, resetPaging )
- Parameters:
Name Type Optional 1 callback
Yes - default:null Function which is executed when the data has been reloaded and the table fully redrawn. The function is given a single parameter - the JSON data returned by the server, and expects no return.
2 resetPaging
Yes - default:true Reset (default action or
true
) or hold the current paging position (false
). A full re-sort and re-filter is performed when this method is called, which is why the pagination reset is the default action.- Returns:
DataTables.Api instance
Examples
Reload the table data every 30 seconds (paging reset):
var table = new DataTable('#myTable', {
ajax: 'data.json'
});
setInterval(function () {
table.ajax.reload();
}, 30000);
Reload the table data every 30 seconds (paging retained):
var table = new DataTable('#myTable', {
ajax: 'data.json'
});
setInterval(function () {
table.ajax.reload(null, false); // user paging is not reset on reload
}, 30000);
Use the callback to update an external elements:
var table = new DataTable('#myTable');
table.ajax.reload(function (json) {
$('#myInput').val(json.lastInput);
});
Related
The following options are directly related and may also be useful in your application development.