java – Vaadin网格表:如何禁用排序功能并设置一列的颜色

前端之家收集整理的这篇文章主要介绍了java – Vaadin网格表:如何禁用排序功能并设置一列的颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Vaadin中使用Grid表进行数据表示.
为此,我试图弄清楚以下两个问题:

1.)如何禁用每列标题中的排序功能

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

解决方法

首先,我发现 Vaadin docs是一个开始寻求帮助的好地方.对于剩下的练习,假设我们有一个带有3个简单列c1,c2和c的网格. C3: @H_502_11@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:

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

或者只是获取所需的一列并设置其可排序属性

@H_502_11@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样式:

@H_502_11@@import "../valo/valo.scss"; @mixin mytheme { @include valo; // Insert your own theme rules here .v-grid-cell.green { background: #33BB00; } }

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

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

哪个应该生成以下内容

猜你在找的Java相关文章