java - 如何在 Vaadin 8 中有条件地为网格行着色?

标签 java sass vaadin vaadin-grid vaadin8

我想根据单元格的值更改 Vaadin 网格行的颜色。我试了下,没用。

SCSS

@import "mytheme.scss";
@import "addons.scss";

// This file prefixes all rules with the theme name to avoid causing conflicts with other themes.
// The actual styles should be defined in mytheme.scss

.mytheme {
     @include addons;
     @include mytheme;

     .v-grid-row.error_row {
            // Tried following elements and didn't work.
            // background-color: red !important;
            // color: blue !important; // This changed the color of the font.
            background: green !important;
     }
}

Java 代码

grid.setStyleGenerator(t -> {
            if (t.getLogLevel().trim().equals(ERROR) || t.getLogLevel().trim().equals(WARN)) {
                return "error_row";
            } else {
                return null;
            }
        });

注意:我从浏览器的开发者工具中检查了 css,显示 css 已正确更新(见下图)。

enter image description here

最佳答案

您需要覆盖该行的 TD 元素的 background-color:

.v-grid-row.error_row > td {
    background-color: red;
}

通过使用浏览器的样式检查,您可以了解 Vaadin 如何实现样式。

关于java - 如何在 Vaadin 8 中有条件地为网格行着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44842348/

相关文章:

css - 在 Angular 6+ (styleExt) 中使用 scss 作为默认样式表

java - 在离开字段时,而不是在 Vaadin 8 Binder 中输入用户类型时,更少地运行 validator

java - 将 JPanel 放置在 JFrame 上

java - 如何检查 Throwable 是否是由无效电子邮件地址导致的

java - Android 手机上到 Rails 服务器的基本 HTTP 身份验证

css - 如何写两个CSS文件 : with and without sourcemap

ruby-on-rails - "Undefined mixin ' box-sizing '", in rails, 使用compass-rails

java - 如何以编程方式禁用 Java LDAP JNDI LDAP API 中的证书主机名验证?

java - Vaadin 网格上下文菜单无法打开/显示

java - Vaadin Push 在 10 中不起作用(流程)