I obtain table data from database via AJAX request. And I need to change data parameter in AJAX request and refresh the table.
I am refreshing table with command
$('#table1').DataTable().ajax.reload();
I have the following code
$('#table1').DataTable({
/* SERVER SIDE PROCESSING */
"serverSide": true,
"ajax":
{
"url": "Home/Search",
"type": "POST",
"data": {
'searchType': GetSearchType(),
'searchText': GetSearchText()
//'searchType': $.mynamespace.searchType
//'searchText': $.mynamespace.searchText
//'searchType': localStorage.getItem("searchType"),
//'searchText': localStorage.getItem("searchText"),
}
}
});
But after AJAX reload, original request to the server is sent and new parameter values are ignored. I tried pass the data to the request via function, global variable and browser storage but none of the approach work. On the internet I find solution with
aoData.push()
function but I don't know how to use it.
My version of jQuery DataTables is 1.10.7.
I also tried destroying and recreating the table with this code:
$('#table1').DataTable({
"ajax":
{
"url": "Home/Search",
"type": "POST",
"data": {
'searchType': GetSearchType(),
'searchText': GetSearchText()
}
},
"destroy" : true
}).ajax.reload();
but I am getting error message:
DataTables warning: table id=table1 - Ajax error (http://www.datatables.net/manual/tech-notes/7)
The parameters dictionary contains a null entry for parameter 'draw' of non-nullable type 'System.Int32'