Identify odd even rows in rowcallback

Identify odd even rows in rowcallback

bbrindzabbrindza Posts: 300Questions: 69Answers: 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,802Questions: 85Answers: 406
    ....
       rowCallback: function (row, data) {
            if ( $(row).hasClass('odd') ) {
                $(row).addClass('text-warning');
            } else {
                $(row).addClass('text-danger');
            }
        }
    ....
    
  • kthorngrenkthorngren Posts: 20,230Questions: 26Answers: 4,755

    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,802Questions: 85Answers: 406
    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.