"draw.dt"

"draw.dt"

davidjpagedavidjpage Posts: 3Questions: 2Answers: 0

Shouldn't the draw event trigger during the initialization of the data table?

Answers

  • allanallan Posts: 64,357Questions: 1Answers: 10,626 Site admin

    It does. However, you probably have the event listener being attached after the initialisation? In which case it will have already triggered - e.g. ( https://live.datatables.net/sijecuve/1/edit ):

    let dt = new DataTable('#example');
    
    dt.on('draw', () => {
      console.log('Doing draw');
    });
    

    The on() call is made after the table has done its initial draw. It does work if you use ajax though since that makes the initialisation async.

    With DataTables 2.3 there is a new on option to resolve exactly this issue ( https://live.datatables.net/sijecuve/2/edit ):

    let dt = new DataTable('#example', {
      on: {
        draw: () => {
          console.log('Doing draw');
        }
      }
    });
    

    on will attach the listeners based on its keys at the start of the initialisation process.

    Allan

Sign In or Register to comment.