Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lazy load items in vaadin grid in LitElement

Tags:

I have a requirement to render infinite scrollable data in an optimal way in LitElement. Vaadin-grid seems suitable for the use-case. However, the data is huge. So I am trying to lazy load the data in chunks from backend. This backend api supports returning records in chunks (such that total number of records will be returned on first call itself). Is there any possible way to lazy load the data in chunks from backend in vaadin-grid with LitElement.

like image 255
Shruti Nath Avatar asked Jul 09 '21 11:07

Shruti Nath


1 Answers

So here is an example from the mentioned starter:

  private async getGridData(params: GridDataProviderParams, callback: GridDataProviderCallback) {
    const index = params.page * params.pageSize;
    const data = await SamplePersonEndpoint.list(index, params.pageSize, params.sortOrders as any);
    callback(data ?? []);
  }

As you can see the params contain page and pageSize that then can be used in the backend for paging.

The SampleEndpoint uses this:

public List<SamplePerson> list(int offset, int limit, List<GridSorter> sortOrder) {
    Page<SamplePerson> page = service
            .list(PagingUtil.offsetLimitTypeScriptSortOrdersToPageable(offset, limit, sortOrder));
    return page.getContent();
}
like image 113
Simon Martinelli Avatar answered Sep 30 '22 19:09

Simon Martinelli