Java, Vaadin 8, lazy loading with grid

狂风中的少年 提交于 2020-01-25 21:35:09

问题


I am trying to implement lazy loading with Grid in Vaadin 8. But it only shows an empty table. What do I do wrong? Also, how do I set the number of items to load (limit) to for example 20 items (the default is 40 items)?

private Grid<Image> makeLazyTable()
{
  Grid<Image> grid = new Grid<Image>();     
  DataProvider<Image, Void> dataProvider = DataProvider.fromCallbacks(
    query -> {
      int offset = query.getOffset();
      int limit = query.getLimit();        
      OffsetRequest request = new OffsetRequest();
      request.setLimit(limit);
      request.setOffset(offset);  
      List<QuerySortOrder> sort = query.getSortOrders();
      return ImagesRepository.findAll(request, sort);
    },
    query -> ImagesRepository.getImageCount()
  );    
  grid.setDataProvider(dataProvider);     
  return grid;
}

回答1:


I did not add any columns. That was the reason why the table was empty. This way it works:

Column<Image, String> filenameColumn = grid.addColumn(Image::getFilename);
Column<Image, String> orientationColumn = grid.addColumn(Image::getOrientation);
Column<Image, String> latitudeColumn = grid.addColumn(Image::getLatitude);
Column<Image, String> longitudeColumn = grid.addColumn(Image::getLongitude);


来源:https://stackoverflow.com/questions/45633226/java-vaadin-8-lazy-loading-with-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!