我想给网格线上色,这取决于条件。我试试这个:
Java:
gridEtudiant.setClassNameGenerator(t -> {
if (t.getEtud_numero().startsWith("2")) {
return "error_row";
}
return "";
});
Css:
td.error_row {
background-color: red;
}
HTML
<td id="vaadin-grid-cell-1" tabindex="0" role="gridcell" part="cell body-cell" first-column="" reorder-status="undefined" aria-selected="false" class="error_row" style="width: 100px; flex-grow: 1; order: 10000000;"><slot name="vaadin-grid-cell-content-1"></slot></td>
我们可以看到“class=”error_row“”,但它不是红色的。
Vaadin版本为13.0.1
发布于 2019-04-09 14:05:03
你的java代码看起来不错。
确保您有一个类似webapp/frontend/styles/shared-styles.html
的html文件,其中包含以下内容:
<dom-module id="my-grid-theme" theme-for="vaadin-grid">
<template>
<style>
[part~="cell"].error_row {
background: red;
}
</style>
</template>
</dom-module>
如果您的布局包含带有@HtmlImport("frontend://styles/shared-styles.html")
注释的网格(您似乎已经拥有了,因为您的自定义css类已经被应用了),那么它应该可以工作。
示例:
grid.addColumn(Customer::getFirstname).setHeader("Firstname");
grid.addColumn(Customer::getLastname).setHeader("Lastname");
grid.addColumn(Customer::getEmail).setHeader("Email");
grid.setClassNameGenerator(customer -> {
if (customer.getFirstname().equals("Marco")) {
return "error_row";
} else {
return "";
}
});
变成:
https://stackoverflow.com/questions/55585042
复制相似问题