我在网格中使用 IndexedContainer。
Grid grid = new Grid();
IndexedContainer container = new IndexedContainer();
grid.setContainerDataSource(container);
container.addContainerProperty("Something", String.class, "");
我需要更改容器属性的名称。例如,单击按钮后将属性“Something”更改为“New property”。有任何想法吗 ?非常感谢!
最佳答案
注 1:您从哪里获得 vaadin 7.8.4?最新7.x release我可以看到是 7.7.10。对于本练习,我假设这是一个拼写错误并使用 7.7.4...
注 2: 不确定是否要仅更改列标题,还是整个属性 ID...如果只是标题,您可以使用:
grid.getColumn("Something").setHeaderCaption("Something else");
据我所知,不可能更改属性。但是,您可以通过删除它并添加新的来解决此问题:
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);
}
}
结果:
关于java - 更改列名称 - Vaadin 7.8.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45423636/