In my Angular2 project, I am utilizing DataTables with the serverSide feature.
After making changes, I am attempting to reload the table and pass these changes as parameters in a POST request via AJAX.
The issue I am encountering is that DataTables always retrieves the options
object from the initialization process, rather than an updated version with the new parameters.
What I aim to achieve is to use ajax.reload()
while passing a fresh set of parameters.
Here is my current function:
filterData(tableParams) {
console.log('reloading DT. tableparams received are: ' + JSON.stringify(tableParams));
let element = $(this.el.nativeElement.children[0]);
let table = element.find('table.dataTable');
table.DataTable().ajax.reload();
}
As shown, the current function does not incorporate the use of tableParams
since I wanted to present a streamlined version. Despite several attempts, I have been unable to find a working solution.
DataTables consistently retrieves the initial options
object containing the initial parameters.
One of my previous attempts looked like this:
filterData(tableParams) {
let element = $(this.el.nativeElement.children[0]);
let table = element.find('table.dataTable');
table.DataTable({
ajax: {
url: this.jsonApiService.buildURL('/test_getUsers.php'),
type: 'POST',
data: tableParams,
},
}).ajax.reload();
}
Your assistance in this matter would be greatly appreciated. If more information or code snippets are needed, feel free to ask. I believe the root of the issue lies with the ajax.reload()
function and the ability to send updated parameters.
Thank you!
Edit 1
This is the initial options
object I have:
let data = {
email: true,
test: 'init',
};
this.options = {
dom: 'Bfrtip',
processing: true,
serverSide: true,
pageLength: 20,
searchDelay: 1200,
ajax: {
url: this.jsonApiService.buildURL('/test_getUsers.php'),
type: 'POST',
data: data,
},
columns: [
{data: 'userId'},
{data: 'userCode'},
{data: 'userName'},
{data: 'userRole'},
{data: 'userEmail'},
],
};
And these are the parameters that DataTables is sending:
https://i.sstatic.net/H43ZV.jpg
(In addition to other DataTables parameters)
Despite my attempts, when I invoke ajax.reload()
, I continue to send the same parameters, hence sticking to the initial settings.