turgos
turgos

Reputation: 1614

Vaadin Grid and LazyQueryContainer

I have linked a Lazy Query Container to Vaadin Grid by following the examples at https://vaadin.com/wiki/-/wiki/Main/Lazy%20Query%20Container/

Those examples require the Query implementations to have a @Override public int size() method. Seems like, Grid uses this method to get the total number of objects will be displayed when container is set.

Size method requires the count and full table scan which is very costly in our case.

Instead of setting size immediately, we would like to change/update it in every loadItems call "@Override public List loadItems(int startIndex, int count) ".

What is the best way of notifying the container (and, eventually the Grid using that container) about the latest known size?

Is there any example of setting the size lazy as well?

Thank you in advance.

Upvotes: 0

Views: 1681

Answers (1)

Alex
Alex

Reputation: 331

I have a solution written with small "cache" and Spring Data Solr. In this case, requests are passed on only when it is required. You can expand or change it for your purposes.

SolrLazyQuery (Pagination) mit Vaadin Grid und Spring Data Solr

final LazyPagedContainer<T> container = new LazyPagedContainer<>(this.currentGenericClass);
container.setLazyQuery(new LazyContainerQuery<T>(firstPage) {

    @Override
    protected Page<T> getPageByNumber(final int pageNumber) {
        final SolrPageRequest solrPage = new SolrPageRequest(pageNumber, PAGE_SIZE, MyGrid.this.currentSort);
        return MyGrid.this.search(solrPage, MyGrid.this.currentSearch, MyGrid.this.currentFilterValues);
    }
});

Vaadin Grid / Table requests to this query: 
startIndex: 0, numberOfIds: 95 
startIndex: 0, numberOfIds: 139 
startIndex: 52, numberOfIds: 171 
startIndex: 137, numberOfIds: 171 
[...] 

Requests to Solr: 
start: 0 rows: 100 
start: 100 rows: 100 
start: 200 rows: 100 
start: 300 rows: 100 
[...] 

Upvotes: 1

Related Questions