天天看点

ajax reload,ajax.reload()

ajax.reload()

Since: DataTables 1.10

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:NameTypeOptional1callbackYes - 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.

2resetPagingYes - 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 = $('#example').DataTable( {

ajax: "data.json"

} );

setInterval( function () {

table.ajax.reload();

}, 30000 );

Reload the table data every 30 seconds (paging retained):var table = $('#example').DataTable( {

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 = $('#example').DataTable();

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.

Events

Options