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.
Issue Tracker
Source Code

Spring Data Provider Add-on version 1.0.0
Initial version

Spring Data Provider Add-on version 2.0.0-alpha1
Initial version for Vaadin 10

Spring Data Provider Add-on version 2.0.0.alpha2
Spring Boot 2 support SpringDataProviderBuilder helper for constructing a data provider This version is for Vaadin 10

Spring Data Provider Add-on version 2.0.0.alpha3
Compatible with Vaadin 10.0.0.alpha11

Spring Data Provider Add-on version 1.1.0
Spring Boot 2 & Vaadin 8

Spring Data Provider Add-on version 2.0.0
Spring Boot 2 support for Vaadin 10 Compiled using Vaadin 10 beta 9 & Spring Data Commons 2.0.6

Spring Data Provider Add-on version 2.0.1
Compiled using Vaadin 10.0.0 instead of beta

Spring Data Provider Add-on version 2.0.2
https://github.com/Artur-/spring-data-provider/releases/tag/2.0.2

Spring Data Provider Add-on version 2.1.0
Built for Spring Boot 2.2

Online