【问题标题】:Change column name - Vaadin 7.8.4更改列名 - Vaadin 7.8.4
【发布时间】:2018-01-07 11:35:51
【问题描述】:

我在网格中使用 IndexedContainer。

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

我需要更改容器属性的名称。例如,单击按钮后将属性“某物”更改为“新属性”。有任何想法吗 ?非常感谢!

【问题讨论】:

    标签: java grid containers vaadin propertygrid


    【解决方案1】:

    注意 1:您从哪里获得 vaadin 7.8.4?我能看到的最新的 7.x release 是 7.7.10。对于这个练习,我假设这是一个错字并使用 7.7.4...


    注意 2: 不确定是要更改列标题还是整个属性 ID...如果只是可以使用的标题:

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

    AFAIK 无法更改 属性。但是,您可以通过删除它并添加一个新的来解决此问题:

    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);
        }
    }
    

    结果:

    【讨论】:

    • 请记住,如果您删除一个属性,您将丢失其上存储的所有数据,并且您必须重新填充它。
    猜你喜欢
    • 2018-01-07
    • 2017-12-29
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多