Is postRemove the right event to count rows in the table?

Is postRemove the right event to count rows in the table?

swrobelswrobel Posts: 10Questions: 2Answers: 0
edited May 2016 in Free community support

The removed row still seems to be present in the DOM on postRemove.

> $('#template tbody').find('tr').length
4

Code:

editor.on('postRemove', function(e, type) {
  console.log($('#template tbody').find('tr').length);
});

Output (first line is from the event handler):

4
> $('#template tbody').find('tr').length
3

If this isn't the right event, what should I be using so I can properly count the rows left in the DOM?

Debug: http://debug.datatables.net/okatej

Also worth mentioning that we have an Editor license, just under a different account at my organization.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,794Questions: 1Answers: 10,513 Site admin
    edited May 2016

    Hi,

    Yes, at the point of the postRemove event the table has not yet been redrawn, so the row is still present (although really in a "detached" state since the next draw will remove it.

    The draw is the next event that happens. The submitComplete event might be the best option here.

    Allan

    edit I've added full forum access to your account now :-)

  • swrobelswrobel Posts: 10Questions: 2Answers: 0

    Allan, thanks for the reply! submitComplete works, but is there any way to listen for that event only when related to a 'remove' event? I noticed that event fires for any editor action that submits back to the server.

  • allanallan Posts: 63,794Questions: 1Answers: 10,513 Site admin
    Answer ✓

    What you could do is:

    editor.on( 'postRemove', function () {
      editor
        .off( 'submitComplete.rows' )
        .one( 'submitComplete.rows', function () {
          ...
        } );
    } );
    

    I've used off and a namespace in case you are using multiple row deletion. postRemove will execute once for each row that was removed.

    Allan

This discussion has been closed.