Hello,
we have implemented lazy Grid loading based on the
Vaadin Blog article
and want to add filters for certain Grid columns. In this case, we do lazy loading by setting a lambda function as a CallbackDataProvider. Please see the code below.
How can we combine CallbackDataProvider with filtering? According to this
StackOverflow post
, the author could solve this problem by using ConfigurableFilterDataProvider as a wrapper over CallbackDataProvider. Sadly, he did not share further code.
Can you please provide us hints how to achieve that?
Our code is fully based on the Blog article and is as follows:
public class Person {
private Long id;
private String firstName;
private String lastName;
private String email;
... getter and setters ...
}
public class PersonService {
public List<Person> findAll(int offset, int limit) { ... }
public int count() { ... }
}
grid.setDataProvider(
(sortOrders, offset, limit) -> {
Map<String, Boolean> sortOrder = sortOrders.stream() .collect(Collectors.toMap(
sort -> sort.getSorted(),
sort -> SortDirection.ASCENDING.equals( sort.getDirection())));
return service.findAll(offset, limit, sortOrder).stream();
},
() -> service.count()
);