3.2.0

Change background color of a grid based on individual element value

Hi,


Im using ActiveWidgets version 2.5.5. The values required by the grid are provided in a .csv file which is already preprocessed. I'm trying to colour individual elements based on the values obtained from the .csv file.

How do i go about doing this? Any help would be appreciated.

Rash
February 9,
This applies to rows :
http://www.activewidgets.com/javascript.forum.10823.5/b4-bug-when-coloring-a.html
And you can do the same for cells:
<script>
var obj = new AW.UI.Grid;
obj.setCellData(function(col, row){return col + "." + row});
obj.setHeaderText("header");

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

obj.setCellEditable(true);

// add new cell property for background color
obj.defineCellProperty("bgColor", function(col, row){

  // lets say we check the text from any cell
  var text = this.getCellText(col, row);

  var cellColor = 'none';
  if (text < 2) {
    cellColor = "#00FF00";
  }
  if (text > 4) {
    cellColor = "red";
  }
  if (text >= 200){
    if (text <=450){
      cellColor = "yellow";
    }
  }
  return cellColor;
}); 

// assign rowBackground to row template style
obj.getCellTemplate().setStyle("background", function(){
return this.getCellProperty("bgColor");
});  

obj.onCellValidated = function(text, col, row){
var template = this.getCellTemplate(col,row);
setTimeout(function(){
template.setStyle("background", template.getCellProperty("bgColor"));
  }, 150);
} 

    document.write(obj);
</script>

February 9,

This topic is archived.

See also:


Back to support forum