How to change text color to a column with render function based on column name not column number

How to change text color to a column with render function based on column name not column number

vatcovatco Posts: 7Questions: 4Answers: 0

Hi,

I'm trying to change the color of a text for couple of my columns but also i have colvis function so when i use render function with the number of the column everything works but if i hide a column for example 5 it's changing the color for the next column.Is there an option to change the color based on column name or something like that?

Here is the part of the code that change the color.Thanks

"rowCallback" : function(row, data, index,full){
if (data.Balance > 0){
$('td:eq(8)', row).css('color', 'red');
}

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,346Questions: 26Answers: 4,776
    Answer ✓

    Try using column().index() to select the column based on visibility. For example:

    "rowCallback" : function(row, data, index,full){
    col = this.api().column(8).index('visible');
    if (data.Balance > 0){
    $('td', row).eq(col).css('color', 'red');
    }
    

    If a column is removed and column 8 shifts left then .index('visible') will take that into account and col will be 7.

    Kevin

  • vatcovatco Posts: 7Questions: 4Answers: 0

    That worked great..Thank you!

This discussion has been closed.