Grid style with setClassNameGenerator

Hi,

I’m trying to set style on the cells of a grid. I’m able to add a class name with setClassNameGenerator but all class style must be defined in the component template ?
I don’t want to set that in the template, is it possible to add it dynamically from java ?

On vaadin 7 I was doing more or less that:

String cssString = "color: red !important;"
com.vaadin.server.Page.Styles.add(".v-table-cell-content-" + cssString.hashCode() + " {" + cssString + "}");

Sylvain

Hi Sylvain. Have you taken a look at the examples for class name generator: https://vaadin.com/components/vaadin-grid/html-examples/grid-styling-demos#generating-class-names-for-grid-cells

Instead of injecting the style dynamically with Java code, which is not supported “directly” in Vaadin 14 (there is low level API to it), it is recommended that you incude it in a .css file and import it with the @CssImport instead.

Why do you want to dynamically inject the style ? Just trying to understand the use case.

Cheers,
Pekka

Because several property are defined by the user on my app and I cannot predefined so much property.
I think I can forge a style attribute with a Renderer but I’m a bit lost

Nobody has an idea to do it with a Renderer ?

I am having the same problem. Did you find a solution yet?