Handle draw callback triggering twice when having fixedColumns

Handle draw callback triggering twice when having fixedColumns

amitmhetre14amitmhetre14 Posts: 3Questions: 1Answers: 0

Hello,

I have draw callback for the datatable having fixedColumns as,

table.on('draw', function(e, settings, json, xhr){
// Logic after table draw
});

With normal datatable (i.e without fixedColumns) this callback trigger only once but this callback triggered twice in case of datatable which has fixedColumns specified.

I think this behavior is due to the fixedColumns as the fixed columns are actually separate table. These fixed tables are then positioned over the original DataTable.

Is there any way we can have this callback to trigger only once even though table has fixedColumns configured? Or are there any parameter with which we can figure out the callback logic is for the main table or for the table which fixed columns?

Thanks,
Amit

Answers

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin

    Hi Amit,

    Can you give me a link to a page showing the issue please?

    Allan

  • amitmhetre14amitmhetre14 Posts: 3Questions: 1Answers: 0
    edited September 2022

    Hi Allan,

    I am trying it on my local, below is the code snippet which I am have.

    var table = $("#example").DataTable($.extend({
          ajax: "/data.json"
          scrollX: true
          sScrollX: "100%"
          sScrollXInner: "110%"
          scrollY: "300px"
          fixedHeader: true
          stateSave: false
          pageLength: 25
          pagingType: "simple_numbers"
          lengthChange: false
          rowId: 'id'
          fixedColumns: { leftColumns: 2 }
        }, {
        "initComplete" : function(){
            // Code
        }
    })).columns.adjust();
    
    table.on('draw', function(e, settings, json, xhr){
        console.log('draw action..')
    });
    

    In this case, log is getting printed twice.

    Regards,
    Amit

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm only seeing single draw events in this example. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • amitmhetre14amitmhetre14 Posts: 3Questions: 1Answers: 0

    Hello Colin,

    Thanks for sharing the live example. Unfortunately I can not share link to a page.
    When I do the column filter/sort it trigger the draw only once(as it is in live example) but it trigger the draw callback twice while initial loading of datatable.

    There might be issue with my code. I am debugging my code further and will update here if I figured out the issue.

    Thanks for your time and support.

    Regards,
    Amit

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited September 2022

    but it trigger the draw callback twice while initial loading of datatable.

    Thats a good hint. Could be something in your initComplete or it could have something to do with ajax loaded data. I tried setting up this example:
    http://live.datatables.net/muwenewa/6/edit

    But it seems there is a problem with using the JS BIN ajax examples. I opened this thread to fix the issue.

    Kevin

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    My example with ajax is now working. It calls draw only once. Please post your initComplete code to see if anything there might be causing an extra draw.

    Kevin

Sign In or Register to comment.