我试图使导出的BeanItemContainer的排序与Vaadin Grid中可见的列相同。我已经花了两天时间试图找到一种方法来做到这一点。但是,我无法找到任何解决方案。
这是我的代码:
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);
}}
在添加容器时,我收到Null Pointer Exception。我不知道如何将已删除的属性放回去。
我只是希望能够以与Grid中显示的顺序相同的方式导出Vaadin Grid中的数据。
非常感谢任何帮助。干杯!