Filtering with Backend DataProvider in Grid

Hi all,

I’m trying to create a backend data provider with server side filtering for a grid. I’ve read the docs through and through, but was not able to find a clue how to set the filter. Reverse engineering the source code, I found the following solution:

DataProvider<Entity, String> dataProvider = new CallbackDataProvider<>(...);
SerializableConsumer<String> filteur = grid.getDataCommunicator().setDataProvider(dataProvider, null);

and to later set the filter,

filteur.accept(filterValue);

It seems to work, but is it the correct way?

Marcus.

Have you checked these parts of the docs?
https://vaadin.com/docs/latest/components/grid#filtering
https://vaadin.com/docs/latest/components/grid#lazy-loading

Yes, I explicitly read that topics.

The “filtering” topic, as far as I understand, only deals with in-memory-filtering. I tried to adapt this, but getListDataView() told me to use getLazyDataView() when working with backend services, which in turn doesn’t offer an option to filter. So I got stuck with this chapter.

The “lazy loading” topic covers backend data provider. I saw that Query parameter contains an optional filter, but I somehow wasn’t able to figure out how to set this filter. I reverese engineered and only found the solution mentioned above.

But, in fact, I totally oversaw this “withConfigurableFilter” thing. I didn’t understand this <Person, Void, PersonFilter> set of generics and I somehow thought PersonFilter would be in memory.

But it isn’t! Thank you for making me read this again. The solution I was searching for was just in front of my eyes. Works perfect and gives the feeling of doing it the correct way.

Thank you!

1 Like