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

有帮助吗?

解决方案

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

其他提示

You can use loadComplete:

loadComplete: function() {
    var gridData = $("#GRID_ID").jqGrid('getRowData');

    for(var i=0; i<=gridData.length; i++) {
        var rowData = $("#GRID_ID").jqGrid('getRowData',i+1);

        if(rowData.col1 == 1) { 
            $("#GRID_ID").jqGrid('setCell',i+1,"col2","",{color:'red'});
        }   
        if(rowData.col1 == 2) { 
            $("#GRID_ID").jqGrid('setCell',i+1,"col2","",{color:'green'});
        }
    }
}

Tell me if it did (or not) work

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top