javascript - How do I reinitialise a Datatable? -


i have page notifications on want refresh every 10 seconds, don't want reload entire page, reload div contains notifications. notifications in datatable, initialised when page loaded, i've been unable reinitialise datatable when div reloaded. div reloads fine normal table. here code:

$(document).ready(function () {     loadnotificationstable(); });  setinterval(reloadnotificationstable, 10000);  function reloadnotificationstable() {     $('#notificationstable').datatable().fndestroy();      $("#notificationsplaceholder").load(location.href + " #notificationsplaceholder>*", "");      $("#notificationsplaceholder").ready(function () {          loadnotificationstable();     }); };  function loadnotificationstable() {     $('#notificationstable').datatable({         ajax: "data.json",         "blengthchange": false,         'idisplaylength': 1000,         "bsort": false,         "bfilter": false,         "sdom": 'ft<"bottom"ilp>',         "bdestroy": false,         "bpaginate": false,         "binfo":false     }); }; 

is able me , show me i'm doing wrong?

try re-initializing datatable after load has finished in callback:

$("#notificationsplaceholder").load(location.href + " #notificationsplaceholder>*",function(data){     loadnotificationstable(); }); 

also add initialization code since want replace table

https://legacy.datatables.net/ref#bdestroy

"bdestroy": true, 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -