I am using plugin jQuery datatables and load my data which I have loaded in DOM at the bottom of page and initiates plugin in this way:
var myData = [
{
"id": 1,
"first_name": "John",
"last_name": "Doe"
}
];
$('#table').dataTable({
data: myData
columns: [
{ data: 'id' },
{ data: 'first_name' },
{ data: 'last_name' }
]
});
SOLUTION: (Notice: this solution is for datatables version 1.10.4 (at the moment) not legacy version):
CLARIFICATION Per the API documentation (1.10.15), the API can be accessed three ways
The modern definition of DataTables (upper camel case):
var datatable = $( selector ).DataTable();
The legacy definition of DataTables (lower camel case):
var datatable = $( selector ).dataTable().api();
Using the new
syntax.
var datatable = ew $.fn.dataTable.Api( selector );
Then load the data like so:
API references:
$.get('myUrl', function(newDataArray) {
datatable.clear();
datatable.rows.add(newDataArray);
datatable.draw();
});
https://datatables.net/reference/api/clear()