[英]Vaadin 14 - Grid::setClassNameGenerator doesn't work
I have a problem with setting a background color for each row in a grid.我在为网格中的每一行设置背景颜色时遇到问题。 I use setClassNameGenerator, but this doesn't work.
我使用 setClassNameGenerator,但这不起作用。 However, if I set the className for the whole grid, then I can see some result.
但是,如果我为整个网格设置 className,那么我可以看到一些结果。 In the end, I want to color the rows based on certain conditions, but for now I just hard-coded one class "failed" to see if coloring works.
最后,我想根据某些条件为行着色,但现在我只是硬编码一个“失败”的类,看看着色是否有效。
Here is my CSS code:这是我的 CSS 代码:
Execution of this snippet doesn't change anything执行此代码段不会改变任何内容
However, this makes the whole background yellow as expected, so the CSS import is ok.但是,这使整个背景按预期变黄,因此 CSS 导入没问题。
Any help would be great.任何帮助都会很棒。 Thanks
谢谢
You say that your last code works "so the CSS import is ok" - No, it's not.你说你的最后一个代码“所以 CSS 导入没问题” - 不,它不是。
It's a huge difference because the row styles need to be defined inside the grid component's scope while setting the background of the whole grid can be done with global css.这是一个巨大的差异,因为行样式需要在网格组件的范围内定义,而设置整个网格的背景可以使用全局 css 来完成。 This is because
Grid
is using a shadow-DOM.这是因为
Grid
使用的是 shadow-DOM。 You canread up on that here , or more extensively here你可以在这里阅读,或者在这里更广泛地阅读
What you need to do in order to load your CSS into the scope of the grid component is add theparameter themeFor = "vaadin-grid"
to the @CssImport
annotation.为了将 CSS 加载到网格组件的范围内,您需要做的是将参数
themeFor = "vaadin-grid"
到@CssImport
注释中。
@CssImport(value = "./styles/failedGridColumn.css", themeFor = "vaadin-grid")
instead of代替
@CssImport("./styles/failedGridColumn.css")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.