I want the value td:eq(2),based on column name instead of writing it as td(2) in the below line

I want the value td:eq(2),based on column name instead of writing it as td(2) in the below line

amitkumarrath123amitkumarrath123 Posts: 1Questions: 1Answers: 0

rowCallback: function (row, dataSet, index) {
if (dataSet.creditDebitFlag == 'C') {
if(isCompanyAgreement){
$(row).find('td:eq(2)').css("background-color", "#D9FEE5");
}
else{
$(row).find('td:eq(4)').css("background-color", "#D9FEE5");
}
}
}

Answers

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406
    edited May 2022

    Assign classes to your columns (ths) in your HTML (class "labels_name" in the example below.)

    Use "columnDefs" to assign the classes used in rowCallback to your tds.

    Example:

    columnDefs: [
        {   targets: "labels_name", className: "labelColCell" },
    ],
    

    and in rowCallback:

    rowCallback: function (row, data) {
        if ( $('.labelColCell', row).text().substr(1, 1) === '-' ) {
            var $labelColor = $('.labelColCell', row).text().substr(0, 1);
                    ......
        }
    }
    
Sign In or Register to comment.