Datatables: How to reload server-side data with additional params

datatables

Solution

Finally got it to work using fnServerParams. Note that I'm both deleting unneccessary params and adding new ones, using a url var object:

    "fnServerParams": function ( aoData ) {
        var l = aoData.length;

        // remove unneeded server params 
        for (var i = 0; i < l; ++i) {

            // if param name starts with bRegex_, sSearch_, mDataProp_, bSearchable_, or bSortable_, remove it from the array
            if (aoData[i].name.search(/bRegex_|sSearch_|mDataProp_|bSearchable_|bSortable_/) !== -1 ){              
                aoData.splice(i, 1);

                // since we've removed an element from the array, we need to decrement both the index and the length vars
                --i;
                --l; 
            }               
        }

        // add the url variables to the server array    
        for (i in oUrlvars) {
            aoData.push( { "name": i, "value": oUrlvars[i]} );
        }
    }

Problem

I have a table which gets its data server-side, using custom server-side initialization params which vary depending upon which report is produced. Once the table is generated, the user may open a popup in which they can add multiple additional filters on which to search. I need to be able to use the same initialization params as the original table, and add the new ones using fnServerParams. I can't figure out how to get the original initialization params using the datatables API. I had thought I could get a reference to the object, get the settings using fnSettings, and pass those settings into a new datatables instance like so: ``` var oSettings = $('#myTable').dataTable().fnSettings(); // add additional params to the oSettings object $('#myTable').dataTable(oSettings); ``` but the variable returned through fnSettings isn't what I need and doesn't work. At this point, it seems like I'm going to re-architect things so that I can pass the initialization params around as a variable and add params as needed, unless somebody can steer me in the right direction. EDIT: Following tduchateau's answer below, I was able to get partway there by using ``` var oTable= $('#myTable').dataTable(), oSettings = oTable.fnSettings(), oParams = oTable.oApi._fnAjaxParameters(oSettings); oParams.push('name':'my-new-filter', 'value':'my-new-filter-value'); ``` and can confirm that my new serverside params are added on to the existing params. However, I'm still not quite there. ``` $('#myTable').dataTable(oSettings); ``` gives the error: ``` DataTables warning(table id = 'myTable'): Cannot reinitialise DataTable. To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destroy the old table and create a new one, set bDestroy to true. ``` Setting ``` oTable.bRetrieve = true; ``` doesn't get rid of the error, and setting ``` oSettings.bRetrieve = true; ``` causes the table to not execute the ajax call. Setting ``` oSettings.bDestroy = true; ``` loses all the custom params, while setting ``` oTable.bDestroy = true; ``` returns the above error. And simply calling ``` oTable.fnDraw(); ``` causes the table to be redrawn with its original settings.

Original source