Is there a way to bring the columns of the DataTable through the API from Ajax? As an example we have this code
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/post.php",
"type": "POST"
},
"columns": [
{ "data": "first_name" },
{ "data": "last_name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
But here the columns are defined by the Javascript itself. I would like to bring along the Ajax of the DataTable itself columns, without having to do Ajax with jquery to fetch the columns and then create the datatable.
Something like this:
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/post.php",
"type": "POST"
},
"columns": data.colunas //ISSO AQUI
} );
} );