簡體   English   中英

如何在Vaadin 8中有條件地為網格行着色?

[英]How to color a grid row conditionally in Vaadin 8?

我想根據單元格的值更改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已正確更新(請參見下圖)。

在此輸入圖像描述

您需要覆蓋行的TD元素的background-color

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

通過使用瀏覽器的樣式檢查,您可以看到Vaadin如何實現樣式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM