Directory

← Back

Pagination

Pagination Add-on for Vaadin

Author

Rating

Popularity

100+

Pagination is a UI component add-on for Vaadin

  • 0.0.4 -> Vaadin 7.x
  • 8.0.6 -> Vaadin 8.0.6 and newer

Java Collection + Pagination Spring Data Jpa + Pagination Vaadin Table + Pagination

Pagination Resources ToString : { currentPage: 1 / 52, limit: 10, offset: 0, pageIndex: 0, fromIndex: 0, toIndex: 10, isFirst: true, hasPrevious: false, hasNext: true, isLast: false, totalCount: 512, initIndex: 0 }

Sample code

public static List<User> userList = new ArrayList<>();
//...

final int page = 1;
final int limit = 20;

final List<User> users = userList.subList(0, limit);
final long total = Long.valueOf(userList.size());

final Table table = createTable(users);
final Pagination pagination = createPagination(total, page, limit);
pagination.addPageChangeListener(new PaginationChangeListener() {
    @Override
    public void changed(PaginationResource event) {
        log.debug("nativeSublist: {}", event.toString());
        table.removeAllItems();
        for(User user : userList.subList(event.fromIndex(), event.toIndex())) {
            table.addItem(user);
        }
    }
});

//...
private Table createTable(List<User> users) {
        final Table table = new Table();
        table.setSizeFull();
        table.setContainerDataSource(new BeanItemContainer<>(User.class, users));
        table.setVisibleColumns("id", "name","email");
        table.setColumnHeaders("ID", "Name","Email");
        return table;
    }

private Pagination createPagination(long total, int page, int limit) {
    final PaginationResource paginationResource = PaginationResource.newBuilder().setTotal(total).setPage(page).setLimit(limit).build();
    final Pagination pagination = new Pagination(paginationResource);
    pagination.setItemsPerPage(10, 20, 50, 100);
    return pagination;
}
@Autowired
UserRepository userRepository;
//...

final int page = 1;
final int limit = 10;

final Page<User> users = findAll(0, limit);
final long total = users.getTotalElements();

final Table table = createTable(users.getContent());
final Pagination pagination = createPagination(total, page, limit);
pagination.addPageChangeListener(new PaginationChangeListener() {
    @Override
    public void changed(PaginationResource event) {
        log.debug("jpaPagable : {}", event.toString());
        Page<User> users = findAll(event.pageIndex(), event.limit());
        pagination.setTotalCount(users.getTotalElements());
        table.removeAllItems();
        for(User user : users) {
            table.addItem(user);
        }
    }
});

//...
public Page<User> findAll(int page, int size) {
    Pageable pageable = new PageRequest(page, size);
    Page<User> users = userRepository.findAll(pageable);
    return users;
}
@Autowired
UserRepository userRepository;
//...

final int page = 1;
final int limit = 10;

final List<User> users = userRepository.findAll();
final long total = users.size();

final Table table = createTable(users.getContent());
table.setWidth(100, Unit.PERCENTAGE);
table.setHeightUndefined();
table.setPageLength(limit);

final Pagination pagination = createPagination(total, page, limit);
pagination.setItemsPerPageVisible(false);
pagination.addPageChangeListener(new PaginationChangeListener() {
    @Override
    public void changed(PaginationResource event) {
        log.debug("tableFindAll : {}", event.toString());
        table.setPageLength(event.limit());
        table.setCurrentPageFirstItemIndex(event.offset());
    }
});

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

Released
2017-05-18
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.0+
Vaadin 8.0+
Browser
Internet Explorer
Firefox
Opera
Safari
Google Chrome
Internet Explorer
Internet Explorer
Internet Explorer

Pagination - Vaadin Add-on Directory

Pagination Add-on for Vaadin Pagination - Vaadin Add-on Directory
Pagination is a UI component add-on for Vaadin - 0.0.4 -> Vaadin 7.x - 8.0.6 -> Vaadin 8.0.6 and newer Java Collection + Pagination Spring Data Jpa + Pagination Vaadin Table + Pagination Pagination Resources ToString : { currentPage: 1 / 52, limit: 10, offset: 0, pageIndex: 0, fromIndex: 0, toIndex: 10, isFirst: true, hasPrevious: false, hasNext: true, isLast: false, totalCount: 512, initIndex: 0 }
Online