Vaadin Grid does not work with too many entries

Ace of Spade :

I created a Vaadin Grid to show some entities, and this worked fine I used a data dataprovider from callback. Now i added 6800000 Entries in the database and grid table is not scrollable anymore, first i tried 1200000 entries and it still worked. I don't understand that because the grid only loads a few entities and not all at ones.

The dataprovider:

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();
});

The grid:

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);

The entity i try to show:

@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.

Thanks for your help.

Tatu Lund :

The amount of the rows in Grid is limited by maximum size of the scroll bar Div element. This is different depending on the browser. For example with default row height you can have some ~880K rows in Chrome, 235K rows in Firefox and 40K rows in IE11.

There is more information here: https://github.com/vaadin/framework/issues/6290

This limitation applies to Vaadin 7 & 8

In Vaadin Flow (v. 10 and later), Grid is totally re-done and its implementation does not have this limitation.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=97267&siteId=1