Function after redrawing a table

Function after redrawing a table

midzmidz Posts: 7Questions: 2Answers: 0

Hello there,
I am building datatable with input in every row (over 4k rows). User can filter and edit every input. After submiting the form, I would like to take all the data and send it to server.

Right now, I am using this to append all rows to first page.
otabulka.rows().nodes().page.len(-1).draw(false);

But after redrawing, I would like to submit form:
$('#hlavni_form').submit();

But I need to submit it after all of the rows where appended. In other words, when the draw function is complete. I am trying to do this:
otabulka.on( 'draw', function () { console.log( 'Redraw occurred at: '+new Date().getTime() ); });

But it does not work. (does not write anything in console).

Thank you for your help.

This question has an accepted answers - jump to answer

Answers

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

    That looks like it should work. And it does here. It doesn't on the very first draw of the table since the event hasn't been added then, but I don't think that's the issue you are seeing).

    Allan

  • midzmidz Posts: 7Questions: 2Answers: 0
    edited July 2018

    Thank you for yor response. Your link is working, but I tried to move "on draw" listener in the click functon:

         $('#button').click(function(){
              otabulka.rows().nodes().page.len(-1).draw(false);
              otabulka.on( 'draw', function () { console.log( 'Redraw occurred at: '+new Date().getTime() ); });
          })
    

    And it stopped working. What do you think is the issue here?

  • midzmidz Posts: 7Questions: 2Answers: 0

    The thing is... when i put the draw listener outside the click, it does work. But it is initiated everytime when somebody filter data etc.

    I need catch the moment when the redrawing is finished (every row is appended to the the first page) and then submit the form :neutral:

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

    You are adding the draw event listener after you call draw(). Add it outside of the click (otherwise its going to add another event listener every time you click the button).

    Thanks,
    Allan

  • midzmidz Posts: 7Questions: 2Answers: 0

    Thank you!

This discussion has been closed.