I am using jqGrid treegrid and want to format the back color of the columns based on the data value in the cell (integer):
Here is an example where I set the column:
{
name: 'missingBooks',
cellattr: function (rowId, tv, rawObject, cm, rdata) {
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 problem is with the cellAttr callback. In this conditional format string:
if (rawObject[11] > 0) {
return 'style="background-color:#FFCCCC"';
}
I would like to reuse this logic, so I don't want to be indexed in rawObject and figure out which column I'm using. I was hoping there was a way to do something like this:
if (rawObject.missingBooks > 0) {
return 'style="background-color:#FFCCCC"';
}
but it looks like undefined. That way, if I add a new column, I don't have to reindex all this conditional formatting code.
source
share