Updating the ajax.data and reloading the datatable
Updating the ajax.data and reloading the datatable
I have a datatable (1.10) that uses an AJAX data source, which accepts a parameter, as below:
var table = $('#example').DataTable( {
ajax: {
url: "http://example.com/end/point",
data: {"id": "12345"}
} );
This works really well.
I have a chart on the page, which when clicked must reload the datatable with the "id"
from the chart element value.
Ideally, i'd like to use something similar to this but with the new "id" parameter included.
table.ajax.url( "http://example.com/end/point").load();
I have tried:
var idSettings = table.settings();
$.extend(true, {}, idSettings, {ajax:{data:{"id":"54321"}}});
table.ajax.reload();
and
var idSettings = table.settings();
idSettings.ajax.data = {"id":"54321"};
table.ajax.reload();
But neither works and when I inspect the settings object the ajax.data hasn't been updated.
Is there anyway to use the API to reload the data based on a new "id"
parameter?
(I'd prefer not to chain the id onto the URL as a string as it feels clumsy)
Answers