Add/Modify ajax options after initialization
Add/Modify ajax options after initialization
Is there a way to dynamically set the ajax error and timeout **after **initialization?
I am initializing a number of datatable objects with some custom columns, but notably without ajax options, because I initially want to display an empty table.
eg.:
var table = domElement.DataTable({
columns: [
{ data: 'name' },
/* ...*/
{ data: 'office' }
]
});
Then at a later stage (based on user interaction), I want the datatable to load data:
table.ajax.url(dynamicUrl).load();
At this stage I ideally want to set not only the url but also an ajax.error function and ajax.timeout. If I initialize the table with these options this works perfectly, like so:
var table = domElement.DataTable({
ajax: {
url: dynamicUrl,
error: function(result) {
if (result.statusText && result.statusText === "timeout") {
console.log('handle-timeout');
}
},
timeout: 5000
},
columns: [
{ data: 'name' },
/* ...*/
{ data: 'office' }
]
});
I know I can work around this by defining the ajax params during initialization and then ensuring that the initial 'dynamicUrl' just returns an empty data attribute. Would be nice if there's a way to avoid that..
Thanks in advance for any feedback
This question has an accepted answers - jump to answer
Answers
No - sorry. You'd need to make the Ajax calls yourself and use
rows.add()
/rows().remove()
if you wanted to do that.Allan
Thanks Allan - I was actually already wondering whether I should do something like rows().remove() in that context - good tip, I'll try that