Changing AJAX function or trigger reload
Changing AJAX function or trigger reload
I wish to show an empty table on initial page load and later trigger a load of AJAX data when dropdowns are used (or button)
If have initialize to use a function for ajax with a closured variabled tableInitial as shown below to first put dummy single row in
"ajax": function (data, callback, settings) {
if (!tableInitial) {
var sUrl = "/api/endpoint-query?someparam=all";
var jqxhr = $.ajax(sUrl)
.done(function (data) {
callback(data);
})
.fail(function () {
alert("error getting data");
});
}
else {
var dummyRow = {data: [[0000,'0000','Make selection above']]};
callback(dummyRow); // Stick empty data in.
}
tableInitial= false;
},
However when using this method there does not seem to be any api to trigger a refresh, the following methods do not work when I use a function:
https://datatables.net/reference/api/ajax.reload()
https://datatables.net/reference/api/ajax.url().load()
..as the ajax property is now undefined.
Also it seems I am not allowed to redefine the ajax property later.
Is there an option here...apart from the obvious of delaying initialization until first use (as that will have display variance issues).
Answers
Looks like I just needed to use:
.DataTable()
https://datatables.net/faqs/#api
Looks like a common mistake