views:

72

answers:

1

i can chance the text color by doing this in jqgrid custom formatter:

function YNFormatter(cellvalue, options, rowObject)
{
    var color = (cellvalue == "Y") ? "green" : "red";
    var cellHtml = "<span style='color:" + color + "' originalValue='" +
                                cellvalue + "'>" + cellvalue + "</span>";

    return cellHtml;
 }

but i want to now change the background color of the whole cell (instead of the text color).

is this possible?

A: 

Here

$("#cell").setCell(Row , Column, Value, { background: '#888888'});

Actually you won't even need custom formatter, if you just intend to do it for setting colors. You can even set color value from here like,

var color = (Value == "Y") ? "green" : "red";
$("#cell").setCell(Row , Column, Value, { background: '#888888', color: color});

Happy Coding.

simplyharsh
@harshh - are you saying to put this line in my custom formatter code function?
ooo
@harshh - i actually want to do it as a custom formatter as i have some conditional logic based on other data properties. Also,where are you getting Row, Column and Value from ?
ooo
@ooo: You should don't use custom formatter. Instead of that you can change the background color of some cells inside of `loadComplete` event. You can get ids of the loaded data with respect of `getDataIDs` method, then get the cell data in a loop with `getCell` examine there and change style of cell with `setCell` using empty string as a data parameter (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods for details). You can also use 'formatter:checkbox' additionally.
Oleg
@harshh - why would i not use a customer formatter?
ooo
You can use any jqGrid features which you like. Usage of custom formatting is in general to produce a HTML code for a cell. To set background color it is enough only set a CSS class on the cell. I would define in you CSS two classes "redBackground" and "greenBackground" and set on the cell only one from the classes. As a formatter I'll use 'formatter:checkbox'. You can do what you prefer.
Oleg
@Oleg - i am doing this in combination with other text formatting on the cell so i already am using a custom formatter. because of this i hoped there was one extra line that allowed me to add background color in this custom formatter function
ooo