Stop ajax call from controls inside jquery datatable
Stop ajax call from controls inside jquery datatable
I have a jquery datatable and it works great with server side processing. However, i am unable to stop ajax calls which are being fired from controls (input and anchor) inside the datatable. I don't know why datatable fires ajax call even from a control inside it.
Here is the columns section:
$("#table-pp").DataTable({
"processing": true,
"order": [[2, "asc"]],
"pagination": true,
"language": {
"infoFiltered": "",
"processing": "Loading. Please wait..."
},
"serverSide": true,
"destroy": true,
"ajax": {
"type": "POST",
"url": "/Site/test/GetData",
"data": { param: XYZ},
"error": function (e) {
},
"dataSrc": function (json) {
json.draw = json.draw;
json.recordsTotal = json.recordsTotal;
json.recordsFiltered = json.recordsFiltered;
return json.data;
}
},"columns": [
{
"title": "Priority", "data": "priority", "width": "200px",
"render": function (data) {
return '<span style="display:none">' + data + '</span><input type="number" class="display-order" onblur="updatePriority(this);" value="' + parseInt(data) + '">';
}
},
{
"data": "id", "orderable": false,
"render": function (id) {
return '<a class="cursor-pointer" onclick="updateStatus(' + id + ', false);">Deactivate</a>';
}
}
]
The problem is that on clicking Deactivate anchor tag and on increasing the counter in input control, both actions fire an ajax call to again get the data from server. I don't want to do it, as i have to update priority and then click a save button to save the data.
Issue is not with binding click event, updatestatus and updatePriority are being called correctly and it gets called before sending ajax request. Thus things are fine here. The problem is the ajax request that is fired as well and it rebinds the data again from ajax call, i don't want that.
This question has an accepted answers - jump to answer
Answers
What do your
updatePriority
andupdateStatus
functions do?Do they perform a table draw? If so that is why the ajax request is being fired.
Kevin
Yes thats what they do, but i don't want to fire an ajax call when i call table.draw; Reason, i am updating some values in table in javascript functions and then want to update the table on client side with the new values.
Is there any way, that in server side processing i can stop ajax call when doing table.draw()?
I don't believe that is an option. The expectation with server side processing is that the data is fetched from the table for each draw. This ensures that the Datatable data shown is accurate based on searches, sorting, etc.
The general idea with server side processing is that any data updates will be sent to the server DB then the
draw()
will fetch the updated data from the server. Depending on your needs its not a requirement to usedraw()
after updating the table.Is this temporary data you are updating?
Maybe you can post your functions and describe what your requirements are so we can see if there are alternatives.
Kevin