Change parameter used in datatables ajax url.Action on Ajax.reload
Change parameter used in datatables ajax url.Action on Ajax.reload
I was wandering if its possible to pass in a different parameter to a controller using Ajax.reload() in datatables.
thanks to topic on stackoverflow, I was able to pass in parameter from my variable in to url.Action on creating the table new { cyfy = "_Switch" })".replace("_Switch",Switch)
Then on button click i change the state of the variable ( to 0 or 1 ) and call Ajax.reload() on my table.
The issues is that controller receives the same parameter value on each reload. It seems that this part is not run with the reload:
"ajax": {
"url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
"type": "get",
"datatype": "json"
},
I was wandering if there is a way to pass in different parameter value on datatables ajax.realod ?
Below bigger part of the code:
$("#toggle").change(function () {
if ($('#toggle').is(':checked') == true) {
Switch = 1
}
else {
Switch = 0
}
/////////////////
var oTable = $('#myDatatable').DataTable({
"bPaginate": false,
dom: 'Bifrtp',
"ajax": {
"url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
"type": "get",
"datatype": "json"
},
This question has an accepted answers - jump to answer
Answers
i tried using
$('#myDatatable').DataTable().ajax.url("GetProjects", "budgeter", 1).load(); but its throwing Invalid JSON response.
sorry for spaming, but i don't seem to be able to edit the comment.
I am trying to add the parameter like below, but it dosent seem to accept that
$('#myDatatable').DataTable().ajax.url("GetProjects", "budgeter", new { cyfy = 0 }).load();
cyfy = 0 // expecting :
Solved. The issue was that Ajax was adding timestamp to the request on the reload.
to solve this I have added cache : true, option while creating a table.
and then I am reloading the table using ajax.url