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?
<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>