1

In Vaadin 13, I'm using grids. In other programs (eg even Excel) one can create "highlights" of the cells (either the whole cell's baground is highlighted in a color, eg yellow or red or the cell font is higlighted is in a different color) depending on a condition. (This is often used to provide quick visual alerts to the user.)

Is there a safe/easy way to achieve this in Vaadin 13? (I couldn't find any "approved/standard" ways of how to do this using Java & Vaadin 13; I'm not very strong with javascript, but can dabble with it if it's the only "right" way to do this....)

Jonathan Sylvester
  • 1,275
  • 10
  • 23

1 Answers1

2

From Vaadin 13 onwards there is setClassNameGenerator method in Grid and Column, which takes lambda as paremeter, returning String. This can be used to produce CSS class name(s) based on e.g. item values. You can then have style module gor the Grid in your shared-styles.html and use these class names there to add e.g. the highlighting of cells etc.

Tatu Lund
  • 9,949
  • 1
  • 12
  • 26
  • Cool, I'll try to see if I can that to work. That said, could "renderers" somehow help here as well? – Jonathan Sylvester Apr 10 '19 at 19:09
  • 2
    Why would you want to use renderers for this purspose? The main goal of renderer is to show the data in the cell using Components, HTML markup or as a text ,for example. (You can find more info about it here under : [Using Renderers in Columns](https://vaadin.com/docs/flow/components/tutorial-flow-grid.html) ) As Tatu suggested, I would go with styles only. The basic idea could be find here : [Vaadin flow: grid conditional background color](https://stackoverflow.com/questions/55585042/vaadin-flow-grid-conditional-background-color/55585859#55585859). – anasmi Apr 11 '19 at 06:29