Reload/refresh table after event
Reload/refresh table after event

I am trying to reload the table but I can't seem to find the way to call the reload function.
In the .done function of the 'revoke' event is where I'm trying to call it $(document).on("click", '.revoke', function (event).
Here is how I'm calling it but fails: $('#example').data.reload(); or table.reload(); or table.ajax.reload();
Any ideas?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596<script>
$(document).ready(function () {
var thedata = GetPermissions();
var table = $('#example').DataTable({
data: jQuery.parseJSON(thedata),
columns: [
{ data: 'Professional' },
{ data: 'Patient' },
{
data: "View",
render: function (data, type, row) {
if (data === true) {
return '<input type="checkbox" checked disabled>';
}
return '<input type="checkbox" disabled>';
}
},
{
data: "Edit",
render: function (data, type, row) {
if (data === true) {
return '<input type="checkbox" checked disabled>';
}
return '<input type="checkbox" disabled>';
}
},
{
data: "Insert",
render: function (data, type, row) {
if (data === true) {
return '<input type="checkbox" checked disabled>';
}
return '<input type="checkbox" disabled>';
}
},
{
data: "Delete",
render: function (data, type, row) {
if (data === true) {
return '<input type="checkbox" checked disabled>';
}
return '<input type="checkbox" disabled>';
}
},
{
data: "Revoke",
render: function (data, type, row) {
return '<input type="button" class="btn btn-danger btn-xs revoke" data-pro="' + row.ProfessionalID + '" data-pat="' + row.PatientID + '" name="revoke" value="Revoke">';
}
}
]
});
$(document).on("click", '.revoke', function (event) {
var sf = $.ServicesFramework(<%=ModuleId %>);
var serviceUrl = sf.getServiceRoot('omnibody');
var revoke = { 'ProfessionalID': $(this).data('pro'), 'PatientID': $(this).data('pat') };
$.ajax({
type: "POST",
cache: false,
url: serviceUrl + "/ModuleTask/RevokeAccessRights",
beforeSend: sf.setModuleHeaders,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(revoke)
}).done(function (result) {
//PROBLEM IS HERE
// $('#example').data.reload();
table.reload();
}).fail(function (xhr, result, status) {
alert('GetPermissions ' + xhr.statusText + ' ' + xhr.responseText + ' ' + xhr.status);
});
});
});
function GetPermissions() {
var sf = $.ServicesFramework(<%=ModuleId %>);
var serviceUrl = sf.getServiceRoot('omnibody');
var jdata;
$.ajax({
type: "GET",
cache: false,
async: false,
url: serviceUrl + "/ModuleTask/GetAccessRightsPivoted",
beforeSend: sf.setModuleHeaders,
contentType: "application/json; charset=utf-8"
}).done(function (result) {
jdata = result;
return jdata;
}).fail(function (xhr, result, status) {
alert('GetPermissions ' + xhr.statusText + ' ' + xhr.responseText + ' ' + xhr.status);
});
return jdata;
}
</script>
ajax.reload()
Since: DataTables 1.10Reload 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):
1234567var
table = $(
'#example'
).DataTable( {
ajax:
"data.json"
} );
setInterval(
function
() {
table.ajax.reload();
}, 30000 );
Reload the table data every 30 seconds (paging retained):
1234567var
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:
12345var
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.
Comments (1)
Reload/refresh table after event
Reload/refresh table after event
Reload/refresh table after event
In this forum response, Allan had mentioned a significant point about the behavior of
ajax.reload()
.ajax.data
when initialized as a static object ie.,So, if
ajax.reload()
has to work for a new set of data inputs, then it is important to initializeajax.data
as a function:Post new comment
Contributions in the form of tips, code snippets and suggestions for the above material are very welcome. To post a comment, please use the form below. Text is formatted by Markdown.
To post comments, please sign in to your DataTables account, or register:
Any questions posted here will be deleted without being published.
Please post questions in the Forums. Comments are moderated.