jquery datatable ajax get data
DataTables Example Using an Ajax Callback
The DataTables ajax option, here is a common way to retrieve
dynamic data from a source, for loading into a table.
$('#example').dataTable( {
"ajax": {
"url": "https://myurl.goeshere.com/mydata",
"type": "POST",
"dataSrc": "my_data"
}
} );
However, you can also use a function with the DataTables ajax option,
instead of an object. Here is an example:
$(document).ready(function() {
var table = $('#demo').DataTable( {
ajax: function (data, callback, settings) {
$.ajax({
url: "http://localhost:7000/ajax-employee-objects",
}).then ( function( json, textStatus, jqXHR ) {
json["data"] = json["row_objects"];
delete json["row_objects"];
//console.log(textStatus); // "success"
//console.log(json.extra_data.foo); // "bar"
callback(json);
});
},
columns: [
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary" }
]
});
} );
Github NathanNoSudo