I generally user ListDataProvider for grids, and if I have a filter field I add a listener to it such as
filterField.addValueChangeListener(event -> {
addFilter();
});
and this is add filter method;
private void addFilter() {
((InMemoryDataProvider<Person>) getDataProvider()).addFilter(person -> {
return filtering(person);
});
}
and filtering method;
private boolean filtering(Person person){
if(person.getName().contains(filterField.getValue())){
return true;
}else
return false;
}
This is a simple version of my filter mechanism, but I generally have multiple filters for grids. But I need to use lazy loading at one of my grids, because the size of the data list is very large. I managed the lazy loading feature by using this code;
setDataProvider((sortOrders, offset,
limit) -> personService.getAll(offset, limit).stream(),
() -> personService.countAll());
But when I use this dataprovider, since it is a CallbackDataProvider , I cant user the filter mechanism that I wrote above, it returns the error,
java.lang.ClassCastException: com.vaadin.data.provider.CallbackDataProvider cannot be cast to com.vaadin.data.provider.InMemoryDataProvider
Is there a way to filter the current data of grid while using lazy loading, I know I can filter the data at database but I don’t want to do filtering at DB.