drawcallback executes with serverside and deferLoading set to 0?

drawcallback executes with serverside and deferLoading set to 0?

mihomesmihomes Posts: 150Questions: 19Answers: 0

Not sure if this is intended behavior or not, but drawcallback executes in this scenario when the page is loaded even though deferLoading=0.

var dt = $('#example).DataTable({
        "serverSide": true,
        "deferLoading": 0, //prevent automatic initial draw of the table
        "ajax":
            {
                "url": "/assets/datatables/somepage.php",
                "type": "POST",
                "data": function ( d ) {
                    d.date_start = dateStart;
                    d.date_start = dateEnd;
                }
            },
        "drawCallback": function() {                
            console.log('draw');
        }

I came across this tonight as I have some code in the callback that uses dt.rows() and because the table hasn't actually been drawn it causes issues with jquery. I was stumped till I realized this code in the callback was the problem and being executed even though deferLoading was 0. Is this correct behavior for drawCallback to still execute in this situation?

The simple workaround is just to check if dt has been initialized first before I run my code, but I wouldn't think the callback would execute if it hadn't.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Yep, drawCallback would still be called - because the table is still drawn. If deferLoading is set, then DataTables uses the data in the DOM for the initial draw, but that still requires a draw.

    Colin

  • mihomesmihomes Posts: 150Questions: 19Answers: 0

    "If deferLoading is set, then DataTables uses the data in the DOM for the initial draw, but that still requires a draw."

    Ahh, that makes sense then. Thanks.

This discussion has been closed.