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;
}
}
jqgrid change the font color of cell based on the value of another cell
-
21-07-2023 - |
Domanda
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
Soluzione
Altri suggerimenti
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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow