I'm using DataTables plug-in to retrieve data from a mysql table and display them. For that I am using their server-side processing code to retrieve all data. So far it's working fine. Now, I am checking the database every minute whether new record is been inserted or not. I am calling data table function if new record is been inserted in database. At the time its clearing entire records and displaying the records with newly inserted records so its look like entire page loads. Can we do without clearing the existing data? or can we append the newly inserted record into existing record without clearing the record? Or how can I process this one?
Here is my code
$('#example').dataTable({
"bProcessing": false,
"bServerSide": true,
"sPaginationType": "full_numbers",
"iDisplayLength":10,
"bDeferRender": true,
"bFilter": false,
"bSort": false,
"bInfo": true,
"sAjaxSource": #PHP_PATH#/json_data"
});
For what you are trying to achieve, I'd also recommend investigating about SignalR - It's awesome!
What are you using bServerSide
Processing for?
The first time your page is generated and sent to the client, the datatable is rendered with what was then latest data. After that, on every subsequent ajax call, if your server sent you back just the new data, all you have to do is call the below method in the success/complete callback.
function AddRow(row) {
$('#example').dataTable().fnAddData([
row[0],
row[1],
row[2]]);
}
$.ajax({
//...
success: function(data) {
//assuming data = ["COL.1", "COL.2", "COL.3"]
AddRow(data);
}
//...
});