سؤال

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