Identify odd even rows in rowcallback

Identify odd even rows in rowcallback

bbrindzabbrindza Posts: 316Questions: 73Answers: 1

How would I identify even/odd rows in a rowCallback function?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,988Questions: 87Answers: 421
    ....
       rowCallback: function (row, data) {
            if ( $(row).hasClass('odd') ) {
                $(row).addClass('text-warning');
            } else {
                $(row).addClass('text-danger');
            }
        }
    ....
    
  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948

    I believe Datatables adds a classnname of odd or even to the rows. You can check to see if its odd or even like this: $( row ).hasClass( 'odd' );.

    Kevin

  • rf1234rf1234 Posts: 2,988Questions: 87Answers: 421
    Answer ✓

    Identical replies overlapping with regard to response time! And yes, Datatables adds those classnames as you suspected, Kevin. I tested my example and it works.

Sign In or Register to comment.