注意 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);
}
}
结果: