2

Is there any particular way to achieve paging/lazy loading in Vaadin tables. I tried to find some documentation , but I couldn't.

3
  • Lazy loading is implemented in the table (and most other components). But for it to work, you need a Container which handles it correctly. Commented Nov 24, 2015 at 9:07
  • Could please tell me a Container type that I van use Commented Nov 26, 2015 at 6:13
  • In what way are your data stored? Commented Nov 26, 2015 at 9:10

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Could you please share a Example Code on how to use this Viritin to achieve Lazyloading
Updated the answer to contain links to "full stack" examples, both against JPA backend, but same approach works against most other backends as well.
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.