jqgrid change the font color of cell based on the value of another cell

Pavy picture Pavy · May 13, 2014 · Viewed 9.2k times · Source

how can we change the font colour of a column based on the value of another column value?

Suppose I have 2 columns, col1 and col2 if col1 has value 1 - col2 should be red in color if col1 has value 2 - col2 should be green in color

Answer

Pavy picture Pavy · May 14, 2014
function fontFormatter(cellValue, opts, rowObject){ 
    switch(rowObject.col1){
        case "1": 
            return '<span style="color:red">'+cellValue+'</span>'; 
        break; 
        case "2" : 
            return '<span style="color:green">'+cellValue+'</span>'; 
        break; 
    } 
}