Filter DataProvider

I using this code to create infinit scroll

myGrid.setDataProvider( (sortOrder, offset, limit) -> protocoloService.findAll(offset,limit).stream(),
    ()-> protocoloService.count().intValue() );

So can I filter this dataProvider?

I try to use myGrid.getDataProvider().

but don`t have the filter method


You have to cast the DataProvider to ListDataProvider… then you’ll see different addFilter methods.

You can also filter lazy data providers, e.g. a CallBackDataProvider; the second type parameter of

DataProvider<POJOTYPE, FILTERTYPE> myProvider = DataProvider.fromFilteringCallbacks(query -> ..., query -> ...); is the type of the Filter object (usually a String). You need to use a configurable filter data provider wrapper object to add a filter dynamically:

ConfigurableFilterDataProvider<POJOTYPE, Void, FILTERTYPE> filteredProvider = dataProvider.withConfigurableFilter(); myGrid.setDataProvider(filteredProvider); Then you can just do this to filter:

filteredProvider.setFilter(filterObject); // maybe filterObject = "myFilterString"; The filter object will find its way to your Query objects as an Optional (see the original fromFilteringCallbacks) and you can use that when doing your backend data queries.


So to answer Fabio’s original question shortly, you need to take your data provider creation out of the setDataProvider() call and use a ConfigurableFilterDataProvider wrapper to add filtering.


Olli, what is a FILTERTYPE?

There is a sample where I can look? or doc? tks


FILTERTYPE in my example is the class of the filter. In actuality it can be something like

DataProvider<MyPojo, String> provider = DataProvider.fromFilteringCallbacks(...) or

DataProvider<MyPojo, Duration> provider = DataProvider.fromFilteringCallbacks(...) but it can be any class you want.

The setFilter method then takes a String in the first case, Duration in the second case and so on.


There’s a real example in the Lazy section of the data model Docs here:

Scroll down to Filtering (it’s quite a long way down).