我正在尝试使导出的 BeanItemContainer 的顺序与 Vaadin Grid 中可见的列相同。我已经花了 2 天时间试图找到一种方法来做到这一点。但是,我找不到任何解决方案。
这是我的代码:
public class TestView extends VerticalLayout implements View{
public static final String VIEW_NAME = "test";
private Grid grid = new Grid();
private BeanItemContainer<PeddlingBeanNestle> bean = new BeanItemContainer<PeddlingBeanNestle>(PeddlingBeanNestle.class);
private ExcelExporter exporter = new ExcelExporter();
@Override
public void enter(ViewChangeEvent event) {
setup();
}
private void setup(){
grid.setColumnReorderingAllowed(true);
grid.setContainerDataSource(bean);
exporter.setContainerToBeExported(bean);
exporter.setCaption("Export");
java.util.List<Grid.Column> a = grid.getColumns();
for (Grid.Column b : a){
b.setHidable(true);
}
grid.addColumnVisibilityChangeListener(new Grid.ColumnVisibilityChangeListener() {
@Override
public void columnVisibilityChanged(Grid.ColumnVisibilityChangeEvent event) {
if(event.isHidden()){
Notification.show(event.getColumn().getPropertyId().toString() +" hidden");
System.out.println(event.getColumn().getPropertyId());
bean.removeContainerProperty(event.getColumn().getPropertyId());
} else {
Notification.show(event.getColumn().getPropertyId().toString() +" displayed");
bean.addContainerProperty(event.getColumn().getPropertyId(), PeddlingBeanNestle.class, "");
}
}
});
grid.addColumnReorderListener(new Grid.ColumnReorderListener() {
@Override
public void columnReorder(Grid.ColumnReorderEvent event) {
Notification.show(grid.getColumns().toString());
}
});
addComponent(grid);
addComponent(exporter);
}}
重新添加容器时出现空指针异常。我不确定如何将已删除的属性放回原处。
我只想能够以与网格中显示的顺序相同的顺序导出 Vaadin 网格中的数据。
任何帮助将不胜感激。干杯!