What event to use AFTER the datatable is fully drawn

What event to use AFTER the datatable is fully drawn

faniefanie Posts: 3Questions: 1Answers: 0
edited June 2018 in Free community support

Hi,

I'm actually searching for an event triggered when the Datatable is fully drawn.

I tried with the 'init.dt' and 'draw.dt' events but nothing...

The draw.dt is triggered after the init.dt, and my datatable is fully visible just some seconds after the trigger of the init.dt

Answers

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

    Hi @fanie ,

    This is similar to another thread I just replied to. Take a look at the example here that I used in that thread. For the init to fire, you need to register the listener before the table is initialised,

    Cheers,

    Colin

  • faniefanie Posts: 3Questions: 1Answers: 0

    Hi,
    thanks for your reply.

    I register it before initialising my table.

    The only solution I have is that:

    $('#myTable')
    .on( 'init.dt', function() {
        //show nothing
        console.log('no access to: ' + $('.dataTables_scroll') );
        setTimeout(function(){
            //show element
            console.log('access to: ' + $('.dataTables_scroll') );
        }, 0);
    })
    .DataTable();
    

    which isn't really academic... and demonstrate there is only milliseconds to wait to have access to the element.

    So I think it may be because of the asynchronous stuff...

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    That looks like it should work: http://live.datatables.net/kolofuqo/1/edit .

    Given that you are using dataTables_scroll I suspect you've removed your initialisation options - perhaps you are using Ajax? Can you link to a page showing the issue please, otherwise I'm afraid we are just guessing.

    Allan

This discussion has been closed.