Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make only the data table auto refresh after every 2 minutes

I am creating inbox mail at automatically refresh after 2 minutes, that displays new mail display in the datatable. How can refresh my datatable?

like image 768
Debasish Avatar asked Dec 02 '25 09:12

Debasish


2 Answers

So you are using serverside processing. sth like this:

$(document).ready(function () {
   var table = $('#TableID').DataTable({
      "processing": true,
      "serverSide": true,
      //any other configuration options
      "ajax": "path/to/processor"
});

you can force it auto refresh making table's ajax param to reload every 120 second:

setInterval(function () {
      table.ajax.reload();
  }, 120000);
like image 177
BehradKhodayar Avatar answered Dec 04 '25 00:12

BehradKhodayar


Considering you're using server-side processing for the Ajax-sourced datatable, all you need to do is redraw the table after every 2 minutes.

You can use Javascript's setInterval() function

var oTable = $("#mytable").DataTable({
                  'serverSide': 'true'
             });

After initialisation, use setInterval() to redraw the table with your desired time.

setInterval(function(){
    oTable.draw();
}, 120000);
like image 32
philantrovert Avatar answered Dec 03 '25 23:12

philantrovert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!