How to update "data" of an already initialized DataTable object?

How to update "data" of an already initialized DataTable object?

mani619cashmani619cash Posts: 1Questions: 0Answers: 0

I have code

var dtParams = {
    "serverSide": true,
    "ajax": {
        "url": "load_items",
        "data": function ( d ) {
            d.extra_data = "old value";
        }
    },
};
var table = $('#main_listing_table').DataTable(dtParams);

Now once table is loaded, I want to modify or add more parameters that "extra_data" without destroying previous object

I tried

//this does not work
table.ajax.data = function (d) {
    d.extra_data = 'new value';
};
//this does not work
table.data('dt_params', {name: 'extra_data': 'new value'});

I can see Network tab its always sending "old value"

Replies

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Yep, it will still call the original function. You need to put the logic into the original function - do a test in there, something like:

            "data": function ( d ) {
                if (condition) {
                  d.extra_data = "old value";
                } else
                  d.extra_data = "new value";
                  d.other_data = "other value";
                } 
            }
    
This discussion has been closed.