Vaadin 8 Grid 不适用于太多条目

Vaadin 8 Grid does not work with too many entries

我创建了一个 Vaadin 网格来显示一些实体,这工作正常我使用了回调中的数据数据提供者。现在我在数据库中添加了 6800000 个条目并且网格 table 不再可滚动,首先我尝试了 1200000 个条目并且它仍然有效。我不明白,因为网格只加载了几个实体,而不是全部。

数据提供者:

this.defaultDataProv = DataProvider.fromCallbacks((query) -> {
    // sorting defaults
    String sort = "sortId";
    Sort.Direction d = Sort.DEFAULT_DIRECTION;
    if (!query.getSortOrders().isEmpty()) {
        // parsing vaadin sort to spring.hibernate sort
        d = (query.getSortOrders().get(0).getDirection() == SortDirection.ASCENDING) ? Sort.Direction.ASC : Sort.Direction.DESC;
        sort = query.getSortOrders().get(0).getSorted();
    }
    Iterable<Article> findAll = this.arService.findAll(query.getOffset(), query.getLimit(), new Sort(d, sort));
    return StreamSupport.stream(findAll.spliterator(), true);
}, query -> {
    return this.arService.cntArticle();
});

网格:

private Grid<Article> articleGrid;
this.articleGrid = new Grid<>("Artikel");
this.articleGrid.setSelectionMode(Grid.SelectionMode.SINGLE);


this.articleGrid.setDataProvider(this.defaultDataProv);
Grid.Column<Article, String> nameColumn = this.articleGrid.addColumn(Article::getName).setCaption("Name").setId("name");
this.articleGrid.addColumn(Article::getEan).setCaption("EAN").setId("ean");
this.articleGrid.addColumn(Article::getSortId).setCaption("Sortid").setId("sortId");
// addColum for stocks
this.articleGrid.addColumn((a) -> {
    return a.getStocks().size();
}).setCaption("Bestände");

articleGrid.addColumn(Article::getCompleteCntStock).setCaption("Zählbestand");
articleGrid.addColumn(Article::getCompleteOldStock).setCaption("Istbestand");

super.addComponent(this.articleGrid);
super.addComponent(this.searchLayout);
super.addComponent(this.filterLayout);
super.addComponent(this.editLayout);
super.setSizeFull();
this.articleGrid.setHeight(500f, Unit.PIXELS);
this.articleGrid.setWidth(1000f, Unit.PIXELS);

我尝试显示的实体:

@Entity
@Indexed
@Getter
@Setter
public class Article implements Serializable {

    private static final long serialVersionUID = -1812015490640296522L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(nullable = false, unique = true)
    @Field(index = Index.YES)
    private Long id;

    @Field(index = Index.YES)
    @Column(nullable = true, unique = true)
    private Long sortId;

    @Field(index = Index.YES)
    @Column(nullable = true, unique = true)
    private Long ean;

    @Column(nullable = false, unique = false)
    private String name;
    private String descr;

    @Column(nullable = false)
    @OneToMany(mappedBy = "article", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @ContainedIn
    private List<Stock> stocks;

    /**
     * Instances the {@link #stocks} with an empty list.
     */
    public Article() {
        stocks = new ArrayList<>();
    }

    /**
     * @return all Stocks summed up.
     */
    public int getCompleteCntStock() {
        int re = 0;
        for (Stock stock : stocks) {
            re += stock.getCntStock();
        }
        return re;
    }

    /**
     *
     * @return all old Stocks summed up.
     */
    public int getCompleteOldStock() {
        int re = 0;
        for (Stock stock : stocks) {
            re += stock.getOldStock();
        }
        return re;
    }
}

This is the grid table but it is not scrollable.

感谢您的帮助。

Grid 中的行数受限于滚动条 Div 元素的最大尺寸。这取决于浏览器。例如,使用默认行高,您可以在 Chrome 中有大约 880K 行,在 Firefox 中有 235K 行,在 IE11 中有 40K 行。

这里有更多信息:https://github.com/vaadin/framework/issues/6290

此限制适用于 Vaadin 7 和 8

Vaadin Flow (v. 10 and later), Grid中完全重做,其实现没有这个限制。