Reputation: 31
Is there any particular way to achieve paging/lazy loading in Vaadin tables. I tried to find some documentation , but I couldn't.
Upvotes: 2
Views: 2043
Reputation: 18925
Lazy loading is completely redesigned and well supported out of the box in Vaadin 8. Here's an example from the official docs:
DataProvider<Person, Void> dataProvider = new BackendDataProvider<>(
// First callback fetches items based on a query
query -> {
// The index of the first item to load
int offset = query.getOffset();
// The number of items to load
int limit = query.getLimit();
List<Person> persons = getPersonService().fetchPersons(offset, limit);
return persons.stream();
},
// Second callback fetches the number of items for a query
query -> getPersonService().getPersonCount()
);
Grid<Person> grid = new Grid<>();
grid.setDataProvider(dataProvider);
Upvotes: 0
Reputation: 1934
Use Viritin add-on and its MTable component. I is the most efficient (server resource vice) way to do it and also has the most simplest API (no need to work with Container APIs at all!). Just implement two simple interfaces and you are done. Here is an example with lambdas and a basic DAO.
@Inject
GPSRouteService s;
@Override
public Component getTable() {
return new MTable<Update>(s::fetchUpdates, s::getEntityCount)
.withFullWidth();
}
The above code example is from this example app, which shows various lazy loading approaches in Vaadin. If you are a Spring user, look at this example, that connects to Spring Data JPA repository and also uses optional sorting support.
I'm maintainer of Viritin, but I have also maintained Vaadin and various add-ons for 7 years and nowadays I'm doing technical marketing for Vaadin.
Upvotes: 3