To set a value in a JQGrid cell based on a condition, you can use the cellattr
function in the colModel
option of the JQGrid.
Here's an example of how you can do this:
javascript$("#grid").jqGrid({
// other JQGrid options here...
colModel: [
// other column options here...
{
name: 'columnName',
index: 'columnName',
width: 100,
formatter: 'text',
cellattr: function(rowId, val, rawObject, cm, rdata) {
if (rawObject.columnName == "someValue") {
return 'style="color:red"'; // set cell color to red
} else {
return ''; // default cell color
}
}
}
]
});
In this example, we're setting the cellattr
option for the columnName
column. Inside the cellattr
function, we're checking if the value of the columnName
cell is equal to "someValue"
. If it is, we're returning the style
attribute with a value of "color:red"
, which will set the cell's text color to red. If the value of the columnName
cell is not equal to "someValue"
, we're returning an empty string, which will set the default cell color.
You can modify the cellattr
function to set the value of the cell instead of its style. For example, you could replace 'style="color:red"'
with 'title="some tooltip"'
to set a tooltip for the cell.
Comments
Post a Comment