How can I update a data table's "ajax.data" function AFTER the table has already been initialized?

How can I update a data table's "ajax.data" function AFTER the table has already been initialized?

triynkotriynko Posts: 6Questions: 2Answers: 0

I need to update/replace the closure function that was originally passed to my datatable.

function closure1(){
};

function closure2(){
};

var table = $(e).DataTable({ajax:{data:closure1}});

When I try to update it like this, nothing happens.

table.ajax.data = closure2;
table.ajax.reload();

I realize that data is actually undefined on the table.ajax property because it's some kind of wrapper, but I'm having trouble getting at the settings object to modify the ajax.data property.

When I call table.ajax.settings() in the Chrome debugger, it shows a plain object, where I can see the 'ajax' property as well as it's 'data' subproperty with the original 'closure1' assigned.
However, at runtime, when I call table.ajax.settings(), it actually returns the original API object wrapper. I can call tabel.ajax.settings().settings().settings() infinitely, and instead of returning a plain object like it does in the debugger, it returns the same API wrapper object over and over. This is very strange behavior and makes no sense.

Answers

  • triynkotriynko Posts: 6Questions: 2Answers: 0

    Upon closer inspection, I see I can change the url with the ajax.url() function, get params with the ajax.params() method, but there is simply no way to alter the data property. There is not ajax.data() method that accepts a new function. This new API is sooooooo locked down, that I just cannot get at anything I need to get at in the table.

  • triynkotriynko Posts: 6Questions: 2Answers: 0
    edited October 2016

    On even closer inspection to the calls that fetch the data, I can see that it's even temporarily deleting the ajax.data property at one point and restoring it at a later point, so it's not even present during the preXhr call for example. This explains why you don't seem to want us altering it after it's been set up. It's honestly kind of a cluster****, and I'm a little disappointed.

This discussion has been closed.