3.0 beta 2

How to set row color based on some column value?

I have a need to set row color to light blue when one of the columns has value TRUE or something similar. How can I do that ?

Thanks
Andrew
Andrew
January 4,
This has been discussed many times before. Do a search of the forums, you will find it.
Jim Hunter
January 4,
I did, could not find any working example.
Search keywords used: row color
Andrew
January 4,
The problem is that I have some dynamic data loading into the model, and want to specify a status (active, passive) in one of the columns.
Based on this value, I need that row to change background every time I reload the data.
Andrew
January 4,
here is an example of what I do to get row background:

getColor = function() {
   // how do I get a value of the single cell in the row
   // and how do I get a row number somewhere here ?
   var value = this.getCellValue(12);
   return value == 'true' ? '#e9f1f5' : 'threedlightshadow';
}

var row = new AW.Grid.Row;
row.setStyle("background", getColor);
grid.setTemplate("row", row);


what is wrong here ?
it says that getCellValue is not a function
Andrew
January 4,
Can anyone tell me how to implement such functionality with v.2 of your library ?

Thanks,
Andrew.
Andrew
January 4,
January 4,
I would like to do it:

1. Per-row basis, but not per cell, I have no idea how many colums will be in my table tomorrow, so I don't want to modify the code every time I add a new column

2. I don't have any javascript array - my model is loaded dynamically
3. I don't have any string like "Under Performing" to search for in my data, I only hve a column with value TRUE in it

thanks,
Andrew
Andrew
January 4,
Hey guys,

can anyone tell me how to get a value of the cell in that code ?
that's all I need: a piece of code to be running in the Row Template that can access some specific cell value.

Guys, I cannot dig through your code to understand your model and figure out how to do it myself, it would take me long time, especially in Javascript, that is NOT object oriented and people use hacks to make it look like one.

Please help...
Andrew
January 5,
1 - Per-cell basis (at least need to know which column contain a true value, but final result in row color)
2 - No model dependant (runs on any model)
3 - No strings searching needed
4 - No hacked code (even no OOP used )
HTH

obj.defineRowProperty("Mybackcolor", function(row){ 
return this.getCellValue(0, row)=='true' ? "red" : "yellow"; 
}); 

for(var i=0;i<obj.getRowCount();i++){
obj.getRowTemplate(i).setStyle("background-color", function(){ 
return this.getRowProperty("Mybackcolor"); 
}); 
}
Carlos
January 5,
thanks Carlos,

but here is the problem:

your code is fine when executed one time, when the grid is rendered. What happens when I reload the data ? number of rows change etc.
Obviously in your example I need to run that code again.

This was the question to the developers of this Grid: how can I access row cell data from the row template, so I can use one of your examples to change the background.

Does anyone know that ?
Andrew
January 5,
To have the custom property apply to all rows, don't bother with the loop:

obj.defineRowProperty("Mybackcolor", function(row){ 
return this.getCellValue(0, row)=='true' ? "red" : "yellow"; 
}); 

obj.getRowTemplate().setStyle("background-color", function(){ 
return this.getRowProperty("Mybackcolor"); 
});
CK
April 5,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.