Directory

← Back

Spring Data Provider Add-on

A data provider for Spring Data with support for paging and filtering

Author

Rating

Popularity

100+

An easy way to connect a Vaadin Grid to a Spring backend.

Only requires you to implement

protected Page fetchFromBackEnd(Query<T, Object> query, Pageable pageable) protected int sizeInBackEnd(Query<T, Object> query) protected List getDefaultSortOrders()

and deals with paging internally.

Sample code

private UserService userService;

@Override
protected Page<User> fetchFromBackEnd(Query<User, Object> query, Pageable pageable) {
	return getUserService().findAnyMatching(getOptionalFilter(), pageable);
}

@Override
protected int sizeInBackEnd(Query<User, Object> query) {
	return (int) getUserService().countAnyMatching(getOptionalFilter());
}

@Override
protected List<QuerySortOrder> getDefaultSortOrders() {
	List<QuerySortOrder> sortOrders = new ArrayList<>();
	sortOrders.add(new QuerySortOrder("email", SortDirection.ASCENDING));
	return sortOrders;
}
public interface PersonRepository extends JpaRepository<Person, Long> {
    Page<Person> findByNameLikeIgnoreCase(String nameFilter, Pageable pageable);
    long countByNameLikeIgnoreCase(String nameFilter);
}

FilterablePageableDataProvider<Person, Object> dataProvider = new FilterablePageableDataProvider<Person, Object>() {
    @Override
    protected Page<Person> fetchFromBackEnd(Query<Person, Object> query, Pageable pageable) {
        return repo.findByNameLikeIgnoreCase(getRepoFilter(), pageable);
    }

    @Override
    protected int sizeInBackEnd(Query<Person, Object> query) {
        return (int) repo.countByNameLikeIgnoreCase(getRepoFilter());
    }

    private String getRepoFilter() {
        String filter = getOptionalFilter().orElse("");
        return "%" + filter + "%";
    }

    @Override
    protected List<QuerySortOrder> getDefaultSortOrders() {
        return Sort.asc("name").build();
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Built for Spring Boot 2.2

Released
2019-11-20
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 10+
Vaadin 8.0+ in 1.0.0
Vaadin 14+ in 2.0.2
Browser
Browser Independent

Spring Data Provider Add-on - Vaadin Add-on Directory

A data provider for Spring Data with support for paging and filtering Spring Data Provider Add-on - Vaadin Add-on Directory
An easy way to connect a Vaadin Grid to a Spring backend. Only requires you to implement protected Page fetchFromBackEnd(Query query, Pageable pageable) protected int sizeInBackEnd(Query query) protected List getDefaultSortOrders() and deals with paging internally.
Online