Problems loading javascript data
Problems loading javascript data
Hi
I am trying to fill two tables using one custom ajax call which returns 2 datasets for 2 tables:
var tx = {data: null, edata: null};
$.ajax({url: '/api'})
.done(function (data){
tx = data;
});
...
var table1 = $('#table1').DataTable({
data: tx,
dataSet: 'data',
scrollY: "300px",
scrollCollapse: true,
paging: false
});
var table2 = $('#table2').DataTable({
data: tx,
dataSet: 'edata',
scrollY: "300px",
scrollCollapse: true,
paging: false
});
The ajax call is invoked after the tables have been initialized, but I cannot get them to show any data. Any suggestions?
Thanks!
Mark
Answers
I already figured it out. Needed to add the following to the ajax callback...
table1.clear();
table1.rows.add(data.data).draw();
table2.clear();
table2.rows.add(data.edata).draw();
Mark