我在 .scss 文件中有这段代码:
.example-table .v-table-header-cell:nth-child(2),
.example-table .v-table-header-cell-desc:nth-child(2) {
background : red;
}
我在 java 中使用它:
table.setStyleName("example-table");
我得到红色的第二个表格标题。
我的问题:如何将参数(在本例中为“2”)从 java 传递到 scss 文件,表格的第二列标题将是红色的?
最佳答案
我不知道你是否可以将参数从 java 传递到 css 但你可以通过在你的表上设置 CellStyleGenerator
来实现你想要的
table.setCellStyleGenerator(new Table.CellStyleGenerator() {
@Override
public String getStyle(Table source, Object itemId, Object propertyId) {
int row = ((Integer)itemId).intValue();
if(row == 2)
return "red-background-style"; // will set this style to every cell in the row
return null;
}
});
有关详细信息,请参阅此示例: https://vaadin.com/docs/-/part/framework/components/components-table.html#components.table.css.cellstylegenerator
关于java - Vaadin 表格标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40488306/