我在Vaadin中使用Grid表进行数据表示.
为此,我试图弄清楚以下两个问题:
为此,我试图弄清楚以下两个问题:
1.)如何禁用每列标题中的排序功能
2.)如何设置网格表中一列的颜色
解决方法
首先,我发现
Vaadin docs是一个开始寻求帮助的好地方.对于剩下的练习,假设我们有一个带有3个简单列c1,c2和c的网格. C3:
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
遍历每个列并将其sortable属性设置为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; } } });
哪个应该生成以下内容: