3.0.0

Setting a cell to a color based on the cell value

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
April 29,
Here is an example -

var obj = new AW.UI.Grid;
obj.setCellData(function(col, row){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(col, row){
    var value = this.getCellValue(col, row);
    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)
April 30,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.