I am trying draw datatable using ajax in it. if I manually create object array of columns it works, but when create columns from initComplete, there is an error "Cannot read property aDataSort", I think initComplete works after drawing table, because in cols array has values after ending datatable initialization. How can I create columns object array after ajax response?
var columnArrayManual = [{"data": "column1"},{"data": "column1"}];
var cols = [];
tblClients = $("#tblClients").DataTable(
{
"ajax": {
"url": "/index.php?controller=controller&act=controllerMethod&ajx=1",
"dataSrc": "data",
type: 'POST',
"data": function (d) {
var a = arguments[0];
return a;
}
},
"initComplete": function (settings, json) {
$.each(json.data[0], function (i, item) {
var col = {"data" : i};
cols.push(col);
})
},
"columns": cols
}
)