加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 05:42:22 所属栏目:Java 来源:网络整理
导读:我在Vaadin中使用Grid表进行数据表示. 为此,我试图弄清楚以下两个问题: 1.)如何禁用每列标题中的排序功能 2.)如何设置网格表中一列的颜色 解决方法 首先,我发现 Vaadin docs是一个开始寻求帮助的好地方.对于剩下的练习,假设我们有一个带有3个简单列c1,c2和c
我在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;
        }
    }
});

哪个应该生成以下内容:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读