javascript - Refresh Datatable with new data -


i have table @ using jquery datatable. table being updated every 15 seconds new data. using latest version of datatable.

how can re-initialise datatable new data without using clear method, impacts ui?

my code:

jquery.ajax({     type: 'post',     url: /list_tasks',     data: ajaxdata,     spinner: true,     success: function (response) {         $('#task_table').html(response.html)         if ( $.fn.datatable.isdatatable('#task_table')) {             $('#task_table').datatable().destroy();         }         var datatable=$('#task_table').datatable({             deferrender:true,             destroy: true,             scrollcollapse: true,             scroller:       true,             scrolly:        "200px",             bfilter:false,             binfo: false,             blengthchange:false,              initcomplete: function(settings, json) {              },             fndrawcallback:function(){              }         });             }    }); 

instead of reinventing wheel should rely on datatables built in ajax feature. if that, can update table easy using ajax.reload() :

var datatable =$('#task_table').datatable( {    ajax: {      url: '/list_tasks',      data: ajaxdata    },    deferrender:true,    scrollcollapse: true,    scroller:       true,    scrolly:        "200px",    bfilter:false,    binfo: false,    blengthchange:false,    initcomplete: function(settings, json) {    },     fndrawcallback:function(){    } });    setinterval(function() {   datatable.ajax.reload() }, 15000); 

update. never able prevent flickering or impact on ui if repeately inject , remove table dom, , instantiate datatable afterwards. approach separate table code in different php script , place inside iframe :

<iframe src="table.php" id="table"></iframe> 

then update iframe each 15 secs :

setinterval(function() {   $('#table')[0].contentwindow.location.reload(true); }, 15000); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -