:: Forum >> Version 2 >>

Setting a cell to a color based on the cell value

More information on this topic is available in the documentation section: /grid.doc.styles/.

Hi,
How can I set the color of a particular cell in a Grid to eg. red or blue
based on whether the value of the cell is eg. < 0 or >= 0 respectively??

Thanks
Bernie
Sunday, April 29, 2007
Here is an example -

var obj = new AW.UI.Grid;
obj.setCellData(function(colrow){return col "." row});
obj.setHeaderText("header");

obj.setColumnCount(10);
obj.setRowCount(10);

// add new property to the cell data model
obj.defineCellProperty("color");

// assign function which calculates color based on cell value
obj.setCellColor(function(colrow){
    var 
value this.getCellValue(colrow);
    if (
value 1){
        return 
"red";
    }
    else {
        return 
"white";
    }
});

// add dynamic background style attribute to the cell template
obj.getCellTemplate().setStyle("background", function(){
    return 
this.getCellProperty("color");
});

document.write(obj);
 
Alex (ActiveWidgets)
Monday, April 30, 2007



This topic is archived.

Back to /grid.doc.styles/

Documentation:

Forum search