Vaadin Grid不适用于太多条目

时间:2018-07-24 06:54:20

标签: java vaadin dataprovider vaadin-grid

我创建了一个Vaadin网格来显示一些实体,并且这很好用,我使用了回调中的data dataprovider。现在我在数据库中添加了6800000条目,并且网格表不再可滚动,首先我尝试了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.

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

网格中的行数受滚动条Div元素的最大大小限制。这取决于浏览器。例如,使用默认行高,Chrome中可以有约88万行,Firefox中可以有235K行,而IE11中可以有40K行。

此处有更多信息:https://github.com/vaadin/framework/issues/6290

此限制适用于Vaadin 7和8

Vaadin Flow(第10版及更高版本)中,Grid被完全重做,其实现没有此限制。