ajax reload not passing the new parameters. I have tried all the suggestions in previous posts but n
ajax reload not passing the new parameters. I have tried all the suggestions in previous posts but n
here is my js initialization code:
''' var table = $('#activityTable').DataTable({
'ajax': {
'url' : 'DoUsagesReports',
'type' : 'POST',
'data': {
'startperiod' : $('#startDatePicker').val(),
'endperiod' : $('#endDatePicker').val(),
'searchText' : $('#searchText').val(),
'customerid': customerID,
'siteid' : $('#sites option:selected').val(),
'userid' : -1,
'pageSize' : rowsPerPage,
'totalRows' : count,
'sortorder' : sortOrder,
'sortcolumn' : sortColumn
}
},
'dom' : 'rt<"bottom" i p>',
...
The reload function is invoked on button click event:
... $('#submitActivityFilters').click(function() {
var selectedSite = $('#sites option:selected').val();
var search = $('#searchText').val();
var startDate = $('#startDatePicker').val();
var endDate = $('#endDatePicker').val();
console.log('Selected Site: ' + selectedSite);
console.log(' Search: ' + search);
console.log(' StartDate: ' + startDate);
console.log(' EndDate: ' + endDate);
$('#activityTable').DataTable().ajax.reload(null, false).draw();
});
I can see the new values in the debugger, looking on the network post, it show the original(initial) values.
What am i doing wrong?
Answers
I figured out. Needed to place the data inside a function:
''' 'ajax': {
'url' : 'DoUsagesReports',
'type' : 'POST',
'data':function(reqData) {
reqData.startperiod = $('#startDatePicker').val();
reqData.endperiod = $('#endDatePicker').val();
reqData.searchText = $('#searchText').val();
reqData.customerid = customerID;
reqData.siteid = $('#sites option:selected').val();
reqData.userid = -1;
reqData.pageSize = rowsPerPage;
reqData.totalRows = count;
reqData.sortorder = sortOrder;
reqData.sortcolumn = sortColumn;
}
},
Now it seems that every time i call the refresh function It does 2 POSTs with increasing dtDraw value
Got it. table.ajax.reload().draw() is wrong. removed the call to draw() and now i get only one post!