Highlight Node before removing it

Highlight Node before removing it

DawidGrzejekDawidGrzejek Posts: 11Questions: 5Answers: 0

Hello,

I correctly remove a row from the table:

var table = $('#userAccountsTable').DataTable();
var s =  id;
table.rows().nodes().each(function(a,b) {
  if($(a).children().eq(0).text() == s){
    table.rows(a).remove();
  }
});
table.rows().invalidate();
table.draw();

But now I would like to highlight that row just before I remove it. I tried something like this:

var table = $('#userAccountsTable').DataTable();
var s =  id;
table.rows().nodes().each(function(a,b) {
  if($(a).children().eq(0).text() == s){
    setTimeout( function () {
      $(table.rows(a)).addClass( 'highlight' );
      setTimeout( function () {
        $(table.rows(a))
            .addClass( 'noHighlight' )
            .removeClass( 'highlight' );
        setTimeout( function () {
            $(table.rows(a)).removeClass( 'noHighlight' );
            table.rows(a).remove();
        }, 550 );
      }, 800 );
    }, 20 );
  }
});
table.rows().invalidate();
table.draw();

But I cannot figure it out.

This question has an accepted answers - jump to answer

Answers

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

    You need to use rows().nodes() to get the tr. E.g., rather than:

    $(table.rows(a)).addClass( 'highlight' );
    

    Use:

    $(table.rows(a).nodes()).addClass( 'highlight' );
    

    Allan

Sign In or Register to comment.