3.2.0

B4 Bug when coloring a row based on a value in a cell

I have the following code to coloring a row based on a value in a cell:

// add new cell properties for foreground/background colors
obj.defineCellProperty("background-color", function(column, row){
//alert('row = ' + row);
var text = this.getCellText(column, row);

var cellColor;
if (text < 200) {
cellColor = "#00FF00";
}
if (text > 450) {
cellColor = "red";
}
if (text >= 200){
if (text <=450){
cellColor = "yellow";
}
}
//alert('setStyle row = ' + row);
obj.getRowTemplate(row).setStyle("background-color", cellColor); // this should work
return cellColor;
});

// assign background-color property to column-1 background
obj.getCellTemplate(2).setStyle("background-color", function(){
return this.getControlProperty("background-color");
});

In B3 it would not show the color for the row until the grid was redrawn either by moving the scrollbar or by sorting. In B4 the color shows but for other than the cell property the row color is off by 1 (higher) and row 0 is not colored at all.
ShepherdOwner
January 23,
Alex ?? Jim?? Please take a look at this.
ShepherdOwner
January 26,
This is not the first issue I have seen where row # was off by one. I have not verified it, but there might be an "off by one" error in the code that Alex might need to find. If I get a chance I'll dig into the code to see if I can spot where the change happened, but right now I don't have the extra time to do that, sorry.
Jim Hunter
January 26,
I guess the problem is that you are trying to assign rowTemplate style from inside background-color method. The correct code should probably look like this (sorry, did not check it :-)

// add new row property for background color
obj.defineRowProperty("background", function(row){

  // lets say we check the text from the column 1
  var text = this.getCellText(1, row);

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

// assign rowBackground to row template style
obj.getRowTemplate().setStyle("background", function(){
  return this.getRowProperty("background");
});
Alex (ActiveWidgets)
January 26,
Alex,

Thanks that does work. I still don't understand why my example wouldn't work, maybe it is a timing issue.
ShepherdOwner
January 27,
obj.defineCellProperty("background-color", function(column, row){
obj.defineRowProperty("background", function(row){
January 27,

This topic is archived.

See also:


Back to support forum