Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Grid cell coloring on row-level condition?
What would be the best way of coloring a grid cell based on a row-entity state?
e.g. If I have an entity like
public class Order {
public enum OrderState { OK, ERROR };
private OrderState state;
private String stateInfo;
}
and I would like to render the stateInfo in green if state==OK and in red if state==ERROR?
Thanks in advance,
Nik
Hi,
Depends on if you want color a single cell or an entire row. For cell-specific stylings, you can use the setCellStyleGenerator method of the Grid and for row stylings you can use setRowStyleGenerator. Both CellStyleGenerator and RowStyleGenerator interfaces have a getStyle method, which has an input parameter that you can query for the row Item or the current cell's Value (and some other things). The getStyle method can then return a string value which will be applied as a CSS class to the cell or the row respectively. After that, just add suitable background-color to the class in your scss file.
Hope this helps,
Olli