Reload table with new POST data
Reload table with new POST data
Hello,
I am not able to find a way to refresh the table with new POST data. The data is fetched from a php script which loads data depending on the POST data I send to the script. If the user changes some settings, I need to send new POST data to the script to get different data back for the table to display.
I create the table with:
activityTable = $('#activityTable').dataTable(
{
"bProcessing": true,
"bServerSide": true,
"ajax": {
"url": "backend/data/activites.php",
"type": "POST",
data: getActivityTableParams()
}, ...
getActivityTableParams just creates a new JSON from the updated user settings, which is needed by the php script to know what data to load.
To refresh the table I use
activityTable.fnReloadAjax( );
which reloads the table, but with the already send POST data from the initialization. getActivityTableParams is not called here.
So what do I have to change?
Thanks in advance
Claus
This question has accepted answers - jump to:
Answers
If you make
ajax.data
a function which then calls yourgetActivityTableParams()
, that should work. As it stands, it's fixed with what the function returns during initialisaton.Colin
Thanks a lot
As a function, the
ajax.data
option can be used to modify the data DataTables submits to the server upon an Ajax request, by manipulating the original data object DataTables constructs internally, or by replacing it completely.This provides the ability to submit additional information to the server upon an Ajax request, with the function being executed upon each Ajax request, allowing values to be dynamically calculated. For example, a value could be read from a text input field to act as an additional search option.
see https://datatables.net/reference/option/ajax.data