Grid filtering + Lazy Loading

Hello,

hopefully somebody can answer this question.

I have a grid with following DataProvider setup:

grid.setDataProvider(
            (sortOrders, offset, limit) -> {
                Map<String, Boolean> sortOrder = sortOrders.stream()
                        .collect(Collectors.toMap(
                                sort -> sort.getSorted(),
                                sort -> sort.getDirection() == SortDirection.ASCENDING));

                return service.findAll(offset, limit, sortOrder).stream();
            },
            () -> service.count()
        );

My service class for that looks like this:

public List<University> findAll(int offset, int limit, Map<String, Boolean> sortOrders) {
        int page = offset / limit;
        List<Sort.Order> orders = sortOrders.entrySet().stream()
                .map(e -> new Sort.Order(e.getValue() ? Sort.Direction.ASC : Sort.Direction.DESC, e.getKey()))
                .collect(Collectors.toList());

        PageRequest pageRequest = new PageRequest(page, limit, orders.isEmpty() ? null : new Sort(orders));
        List<University> items = universityRepository.findAll(pageRequest).getContent();

        return items.subList(offset%limit, items.size());
}

public Integer count() {
		return Math.toIntExact(universityRepository.count());
}

Now I want to add a filter row to the grid with multiple filters. How can I achieve this?

I have read something about ConfigurableFilterDataProvider on this page https://vaadin.com/docs/v8/framework/datamodel/datamodel-providers.html#lazy-filtering but it didnt help me.

Nobody who can help?

Yacin Damha:

Now I want to add a filter row to the grid with multiple filters. How can I achieve this?

I have read something about ConfigurableFilterDataProvider on this page https://vaadin.com/docs/v8/framework/datamodel/datamodel-providers.html#lazy-filtering but it didnt help me.

How did the ConfigurableFilterDataProvider not help ?
Build a filter by combining the filter row input ( The Filter can be a Simple Pojo containing all the input from your filter row). Convert that to something your service can use.

For JPA projects I usually use the Filter to generate the query using the CriteriaApi…

Thanks for you answer. Could you show a simple code example?