Draw and Length Params Not Being Sent in Server Side Processing
Draw and Length Params Not Being Sent in Server Side Processing
I was initially having difficulty getting my table to refresh with new data form new parameters using ajax.reload(). The problem appeared to be that it was using the same parameters that I had set during initialization, and the fix was to make the ajax data parameter a function.
After doing this, I see that the updated parameters are being passed in the ajax call, however my query on the back-end is failing because draw and length are no longer being passed. According to the server side manual (https://datatables.net/manual/server-side), these are two params that DataTables itself will send out. However, it looks like that is not the case when data is made a function.
Will I have to manually set up the start,m length, and draw options, and then keep track of them, or is there something I am missing here?
Original code segment:
var table = $('#example').DataTable({
cache: false,
scrollCollapse: false,
paging: true,
pagingType: 'simple_numbers',
lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All']],
searching: false,
info: false,
processing: true,
serverSide: true,
ajax: {
url: myURL,
data: {
campus: $("#campus").val(),
college: $("#college").val(),
year: $("#year").val() };
}
}
});
Updated code segment:
var table = $('#example').DataTable({
cache: false,
scrollCollapse: false,
paging: true,
pagingType: 'simple_numbers',
lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All']],
searching: false,
info: false,
processing: true,
serverSide: true,
ajax: {
url: myURL,
data: function () {
return {campus: $("#campus").val(), college: $("#college").val(), year: $("#year").val() };
}
}
});
This question has an accepted answers - jump to answer
Answers
Hi @sjmcarter ,
I suspect it's because your function is over-writing the data, not adding to it.
Try,
Cheers,
Colin
Thanks Colin. So is d the data object that gets sent in server side requests?
Thanks, Colin. I think that was the piece I was missing!