WebDBGrid Cell background color

Is there a way to change the background/brush color on a cell based on a value?  If the database field value for a cell is = green, paint the cell background color green for example?


I was looking through the demo's and didn't see anything allowing that kind of control on individual cells for the WebDEGrid.

-Scott

You can use the OnGetCellChildren event. 
This event is triggered for each cell and returns the cell HTML TD element via AElement parameter.
There you could set a style property depending on cell value, i.e.

AElement.style.setProperty('background-color','red');

Ahhh  I didn't even think to use the Element Style.  Nice!  


Thanks,
Scott

to paint entire row ? or better to have a row selection in OnGetCellChildren or DblClickCell event ?

bye

If what you need is indicated selected row, set goRowSelect = true in grid.Options, then you do not need to deal with cell clicking.

I use WebDBTableControl, i can ?

If you create a CSS class to set a background color, you can make an entire row colored using something like:

<style>
 .redcell { background-color: red; }
</style>

procedure TForm3.WebTableControl1GetCellClass(Sender: TObject; ACol,
  ARow: Integer; AField: TField; AValue: string; var AClassName: string);
begin
  if arow = 5 then
    AClassName = 'redcell';
end;

ok bruno go fine , but i must restore 'natural' rows color of entire grid before selecting another , otherwise i have many rows red !

Hello!

The problem with this is that the selected row color is not applied in those rows that have.

The solution would be to set a different CSS style for the selected row, but how to know which is selected?

grid.Row: integer property has the index of the selected row