Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Making Table class compatible with pagination

Christopher Cobb
10 years ago Mar 26, 2012 6:30pm
Christopher Cobb
10 years ago Mar 26, 2012 7:06pm
Christopher Cobb
10 years ago Mar 27, 2012 4:11pm

I have finished my testing and confirmed that the above change is the only change necessary to vaadin code to make pagination work.

My requirements were a paginated table that supported filtering. I first tried to use Jens Jansson's PagedTable, but that did not directly support filtering.

I modified that code to use an IndexedContainer (which does support Filtering) instead of the PagedTableContainer.

Table and its base classes already seemed to have much of the support I needed to support pagination with filtering. The only change needed was to add a protected method to the Table class:
[indent] protected int maxIndex(int size, int length) {[indent] return size - length;[/indent]}[/indent]
and call it from two places in the same class:

line 984: int maxIndex = maxIndex(size(), pageLength);

line 1273: int maxIndex = maxIndex(size, pageLength);

I have attached three files which contain the new implementation:

  1. PagedTable.java -- the modified implementation (notice that maxIndex() is overridden)
  2. PageChangeListener.java -- separated out from PagedTable.java so it could be called from the filter
  3. PositionManagementFilters.java -- uses SimpleStringFilter along with PagedTable

The paging behavior is the same as with the original PagedTable. However, with filtering, the total number of pages will change, depending on the results of the filter.

Also, there is a scroll bar along the side of the table. I think I could have made this go away with a filter which filtered out all rows except the ones visible on the current page. However, this filter would have to have been applied LAST. The current vaadin implementation of filters uses a HashSet, which doesn't preserver order. So I don't think it is possible without using a Set implementation that does preserve order.

On the other hand, I like having a functioning scroll bar along with the paging controls. Sometimes you just want to scroll up or down a little, in which case you can use your mouse's scroll button. If you want to jump around between pages, you can use the page controls.

Using the pagination controls will move the scroll bar, but using the scroll bar will not change the "current page" field. I have not yet investigated what it would take to have movement of the scroll bar also update the "current page" field. Can anyone tell me if this is possible?

Anyway, my preliminary tests are working. Please have a look.

It would be great if these minor changes to the Table class could make it into 7.0.0.alpha2!

Thank you in advance.

Last updated on Mar, 27th 2012