Grid with lazy data view and filter


I’ve implemented a DataProvider by implementing FetchCallback with a filter.
I was planning to access to the filter value object in the fetch method through query.getFilter() to pass that through to the repository to fetch only the records I need.

However now I see that the grid is expecting an implementation of FetchCallback<Foo, Void> and doesn’t accept my implementation of FetchCallback<Foo, MyFilter>

What would be the best approach to pass a filter object through the dataprovider to the repository and still have lazy loading?

I could switch to a ListDataProvider and do in memory filtering, but I’m a bit concerned about the amount of data.

Any suggestions on how to best approach this?


Don’t we have example for that in our docs :thinking:

You should simply ignore the filtering API in data binding. It was bit of over-engineered at some point. When changing the filters, simply change/reset the databinding.

Keeping the same data binding and calling refreshAll don’t give you any performance gains.

Here is a quick example I just drafted: Comparing vaadin:v23...mstahv:example/add-lazy-data-binding · vaadin/flow-crm-tutorial · GitHub

This ListView class shows you how the updateList method is called from the filter text field. Same principle with multiple filters. flow-crm-tutorial-with-eclipse-serializer/src/main/java/com/example/application/views/list/ at example/add-lazy-data-binding · mstahv/flow-crm-tutorial-with-eclipse-serializer · GitHub

Found the official docs: Binding Items to Components | Data Binding | Vaadin Docs

Docs are here: but I always find it hard to find

Edit: should have read all replies before opening google :sweat_smile:

Hi @quintessential-ibex,

Thanks a lot for this example! I’ll give it try tomorrow first thing.

I was indeed somehow expecting that overriding the data provider in setItems was a heavier operation than calling refreshAll with the filter passed through to the data provider and the query.

@quirky-zebra thank you for the reference! I was looking for it because I indeed remembered reading something.

I think it’s because “Filtering in-memory data” has it’s own section, while “Filtering with Lazy Data Binding” is hidden beneath “Lazy data binding using callbacks” that it’s a bit harder to find.

Thanks to you both!
Really helpful :slightly_smiling_face: