Search code examples
jqgridjqgrid-formatter

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


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


Solution

  • 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; 
        } 
    }