i am using jqGrid treegrid and i want to format the back color of columns based on the value of the data in the cell (its an integer):
Here is an example where I setup the column:
{
name: 'missingBooks',
cellattr: function (rowId, tv, rawObject, cm, rdata) {
//conditional formatting
if (rawObject[11] > 0) {
return 'style="background-color:#FFCCCC"';
}
},
width: 75,
unformat: originalValueUnFormatter,
formatter: missingBooksFormatter,
align: "right",
index: 'missingBooks',
hidden: false,
sorttype: 'int',
sortable: true
},
this works fine but my issue is in the cellAttr callback. In this conditional formatting line:
if (rawObject[11] > 0) {
return 'style="background-color:#FFCCCC"';
}
i would like to reuse this logic so i dont want to have to index into the rawObject and figure out what column i am using. i was hoping there was a way to do something like this:
if (rawObject.missingBooks > 0) {
return 'style="background-color:#FFCCCC"';
}
but this seems to be undefined. This way if i add a new column i dont have to reindex all of this conditional formatting code.