Redraw on drawCallback?

Redraw on drawCallback?

morissettemorissette Posts: 16Questions: 4Answers: 1
mainTable = $("#main_dash").dataTable({
    "language": {
        "url": "../locale/" + locale + "/LC_MESSAGES/" + "dt." + locale + ".txt",
    },
    "pagingType": "full_numbers",
    "pageLength": 10,
    "processing": true,
    "ajax": {
        "url": "ajax_tables/main_table.php",
        "type": "POST"
    },
    "columnDefs": [
        { "orderable": false, "targets": 0 }
    ],  
    "columns": [
        {"data": "flagged"},
        {"data": "date"},
        {"data": "type"},
        {"data": "regarding"},
        {"data": "submitted_by"},
        {"data": "review"},
        {"data": "assign"},
    ],  
    "autoWidth":false,
    "order": [[1, 'asc']],
    "deferRender": true,
    "drawCallback": function() {
        setTimeout(function() {

        }, 20000);
    },
});

How do I redraw?

This question has an accepted answers - jump to answer

Answers

  • morissettemorissette Posts: 16Questions: 4Answers: 1

    Actually I don't think I want to redraw I want to update the data in the table... anything that can be done without the API?

  • morissettemorissette Posts: 16Questions: 4Answers: 1

    Trying:

        "drawCallback": function() {
            setTimeout(function() {
                mainTable.ajax.url("ajax_tables/main_table.php").load();
            }, 20000);
        },
    
  • morissettemorissette Posts: 16Questions: 4Answers: 1
        "initComplete": function() {
            setTimeout(function() {
                mainTable.ajax.url("ajax_tables/main_table.php").load();
            }, 5000);
        },
    

    I went with that, but this only refreshes after the first time, how do I reload every 5 seconds always?

  • morissettemorissette Posts: 16Questions: 4Answers: 1
    Answer ✓

    I used setInterval instead of setTimeout. This is resolved

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Nicely done - setInterval is the way to do it. It can also be cancelled with clearInterval if you ever need to.

    Allan

This discussion has been closed.