更改列名 - Vaadin 7.8.4 [英] Change column name - Vaadin 7.8.4

查看:168
本文介绍了更改列名 - Vaadin 7.8.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网格中使用了IndexedContainer。

  Grid grid = new Grid(); 
IndexedContainer container = new IndexedContainer();
grid.setContainerDataSource(container);
container.addContainerProperty(Something,String.class,);

我需要更改容器属性的名称。在点击按钮之后,将某物属性改为新物业。有任何想法吗 ?非常感谢!

解决方案

注1:您从哪里获得vaadin 7.8.4?我可以看到最新的7.x


I use IndexedContainer in my grid.

Grid grid = new Grid();
IndexedContainer container = new IndexedContainer();
grid.setContainerDataSource(container);
container.addContainerProperty("Something", String.class, "");

I need to change the name of the container property. E.g property "Something" to "New property" after the click on the button. Any ideas ? Thank you very much !

解决方案

NOTE 1: Where did you get vaadin 7.8.4 from? The latest 7.x release I can see is 7.7.10. For this exercise I'll assume it's a typo and use 7.7.4...


NOTE 2: Not sure whether you want to change just the column caption, or the entire property id... If it's just the caption you can use:

grid.getColumn("Something").setHeaderCaption("Something else");


AFAIK it's not possible to change a property. However, you can work around this by removing it and adding a new one:

public class MyGridWithChangeableColumnHeader extends VerticalLayout {
    public MyGridWithChangeableColumnHeader() {
        // basic grid setup
        Grid grid = new Grid();
        IndexedContainer container = new IndexedContainer();
        grid.setContainerDataSource(container);
        container.addContainerProperty("P1", String.class, "");
        container.addContainerProperty("Something", String.class, "");
        container.addContainerProperty("P3", String.class, "");

        // button to toggle properties
        Button button = new Button("Toggle properties", event -> {
            String oldProperty, newProperty;
            if (container.getContainerPropertyIds().contains("Something")) {
                oldProperty = "Something";
                newProperty = "Something else";
            } else {
                oldProperty = "Something else";
                newProperty = "Something";
            }

            container.removeContainerProperty(oldProperty);
            container.addContainerProperty(newProperty, String.class, "");
            grid.setColumnOrder("P1", newProperty, "P3");
        });

        addComponents(grid, button);
    }
}

Result:

这篇关于更改列名 - Vaadin 7.8.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆