gpt4 book ai didi

java - Vaadin 网格表 : How to disable Sort Function and set the color of one column

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:52:26 27 4
gpt4 key购买 nike

我在 Vaadin 中使用 Grid 表来表示数据。为此,我试图找出以下两个问题:

1.) 如何关闭每列表头的排序功能

2.) 如何设置Grid 表格中一列的颜色

最佳答案

首先,我找到了 Vaadin docs一个开始寻求帮助的好地方。对于练习的其余部分,假设我们有一个包含 3 个简单列 c1、c2 和 c3 的 Grid:

Grid grid = new Grid();
grid.addColumn("c1", String.class);
grid.addColumn("c2", String.class);
grid.addColumn("c3", String.class);



1.) How to disable the sort function in the Header of each column

遍历每一列并将其可排序属性设置为false:

for (Grid.Column column : grid.getColumns()) {
column.setSortable(false);
}

或者只获取您想要的那一列并设置其可排序属性:

grid.getColumn("c1").setSortable(false);



2.) How to set the color of one column in a Grid table

类似于它的方式was done with the table ,您需要在 theme 中定义您的 CSS 样式:

@import "../valo/valo.scss";

@mixin mytheme {
@include valo;
// Insert your own theme rules here

.v-grid-cell.green {
background: #33BB00;
}
}

并使用 CellStyleGenerator将样式应用于所需的列:

grid.setCellStyleGenerator(new Grid.CellStyleGenerator() {
@Override
public String getStyle(Grid.CellReference cellReference) {
if ("c1".equals(cellReference.getPropertyId())) {
return "green";
} else {
return null;
}
}
});

应该生成如下内容:

enter image description here

关于java - Vaadin 网格表 : How to disable Sort Function and set the color of one column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35602385/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com