Reload table with new POST data

Reload table with new POST data

ThalliusThallius Posts: 31Questions: 4Answers: 0

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    If you make ajax.data a function which then calls your getActivityTableParams(), that should work. As it stands, it's fixed with what the function returns during initialisaton.

    Colin

  • ThalliusThallius Posts: 31Questions: 4Answers: 0

    Thanks a lot

  • booleanboolean Posts: 1Questions: 0Answers: 1
    Answer ✓

    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

This discussion has been closed.