I am using DataTables serverSide in an Angular2 project.
I am trying to reload the table after making changes, and those changes I want to pass them as parameters in POST via AJAX.
The thing is that DataTables is always getting the options
object from the initialization, and not an updated version with the new parameters.
So, what I need is, to use ajax.reload()
passing a new set of parameters.
This 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();
}
At the moment, as you can see, I'm not using tableParams
, this is because I wanted to show a clean version of my function, I tried many things and none of them worked.
DataTables always gets the initial options
object, with the initial parameters.
This is one of my desperate attempts:
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();
}
Some help would be much appreciated. If you need further explanations on how the DataTable is created, or more code snippets let me know. But I think that the issue is just with the ajax.reload()
function, being able to send updated parameters will solve the issue.
Thanks very much!
Edit 1
This is my init options
object:
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:
(Among other DataTables parameters)
When I call ajax.reload()
, no matter the things I have tried, I end up sending these same parameters, therefore, sending the init parameters.