Reputation: 881
I'm using DataTables 1.11.3 and load data by ajax like this, and all events catchers work ok. But if I remove ajax option and put "data": ta_data, events don't work at all, no one. Then if I put by button 'cklick' ajax source and redraw events work again Events don't work with static load data from local variable data ?
$(document).ready(function(){
"use strict";
const ta_data = JSON.parse(ta).data;
let table_arch = $("#datatable-archive").DataTable({
"scrollY": '60vh',
"scrollX": false,
"paging": false,
"searching": false,
"info": false,
"order": [[ 10, "desc" ]],
"ajax": {
"url": 'rest/data/history/' + last_date,
"error": function(a,b,c){showErrorModal(a,b,c); offSpinner();}
},
})
.on( 'preDraw', function() {sp = {buy:0, sell:0, buyErr:0, sellErr:0};})
.on( 'draw.dt', function() {
$.when(offSpinner()).then(
function(){
gageMaker(sp, "Accuracy");
commonDonut();
}
)
});
});
Upvotes: 0
Views: 230
Reputation: 881
It's necessary to change order. First set event catchers then initialize the table
const ta_data = JSON.parse(ta).data;
let table_arch = $("#datatable-archive"))
.on( 'draw.dt', function() {
$.when(offSpinner()).then(
function(){
gageMaker(sp, "Accuracy");
commonDonut();
}
)
}).DataTable({
"scrollY": '60vh',
"scrollX": false,
"paging": false,
"searching": false,
"info": false,
"order": [[ 10, "desc" ]],
"data" : ta_data
},
})
Upvotes: 1