Vaadin Grid Table:如何禁用排序功能并设置一列的颜色
Vaadin Grid Table : How to disable Sort Function and set the color of one column
我在 Vaadin 中使用 Grid
table 进行数据表示。
为此,我试图找出以下两个问题:
1.) 如何关闭每列表头的排序功能
2.) 如何设置Grid
table
中一列的颜色
首先,我发现 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, you need to define your CSS style in your theme:
@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;
}
}
});
应该生成如下内容:
这里是对Morfic good 的一个小补充:
1.) How to disable the sort function in the Header of each column
网格询问容器列是否可排序(参见网格中的 appendColumn 方法)。如果您想禁用所有列的排序,您可以覆盖容器中的 getSortableContainerPropertyIds 和 return 一个空集合:
container = new BeanContainer<String, Dive>(Dive.class) {
@Override
public Collection<?> getSortableContainerPropertyIds() {
LinkedList<Object> sortables = new LinkedList<Object>();
return sortables;
}
};
我在 Vaadin 中使用 Grid
table 进行数据表示。
为此,我试图找出以下两个问题:
1.) 如何关闭每列表头的排序功能
2.) 如何设置Grid
table
首先,我发现 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, you need to define your CSS style in your theme:
@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;
}
}
});
应该生成如下内容:
这里是对Morfic good
1.) How to disable the sort function in the Header of each column
网格询问容器列是否可排序(参见网格中的 appendColumn 方法)。如果您想禁用所有列的排序,您可以覆盖容器中的 getSortableContainerPropertyIds 和 return 一个空集合:
container = new BeanContainer<String, Dive>(Dive.class) {
@Override
public Collection<?> getSortableContainerPropertyIds() {
LinkedList<Object> sortables = new LinkedList<Object>();
return sortables;
}
};