代码之家  ›  专栏  ›  技术社区  ›  SDS

Vaadin 8网格分页

  •  1
  • SDS  · 技术社区  · 7 年前

    我正在尝试实现类似于vaadin 8网格表的分页。 我尝试使用附加组件 https://vaadin.com/directory#!addon/pagination 但它不适用于Vaadin 8网格。有人尝试过实现分页吗?? 我使用的Java网格API如下所示:

        msgGrid = new Grid();
    
        if (input != null) {
            msgGrid.setItems(input);
        }
        msgGrid.setColumnReorderingAllowed(true);
        msgGrid.setHeaderVisible(true);
        msgGrid.setResponsive(true);
        msgGrid.setRowHeight(25);
    

    如果你能分享一些信息,我将不胜感激。 蒂亚

    1 回复  |  直到 7 年前
        1
  •  3
  •   TacheDeChoco    7 年前

    Grid<Sample> datagrid;
    Pagination pagination;
    
    
    datagrid = new Grid<>();  
    ...
    PaginationResource paginationResource = PaginationResource.newBuilder().setPage(1).setLimit(limit).build();
    pagination = new Pagination(paginationResource);
    pagination.setItemsPerPage(10, 20, 50, 100);
    pagination.addPageChangeListener( event -> onPageChange(event.fromIndex(), event.toIndex()) ); 
    
    /**
     MyResultSet is a structure containing
     - a list of <Sample> beans (accessible by getList())
     - a integer with the total number of records (accessible by getTotalnumber())
     */
    private void onPageChange(int fromIndex, int toIndex) {     
            MyResultSet data = loadSampleRecords(fromIndex, toIndex);
            this.pagination.setTotalCount( data.getTotalnumber() ); 
            this.datagrid.setItems( data.getList() );
            this.datagrid.getDataProvider().refreshAll();
            this.datagrid.scrollToStart();  
        }