![](/img/trans.png)
[英]How to set cell color in Vaadin 8 Grid only if row is not selected
[英]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.