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,


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,

Ah, thanks, that appears to be it.