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:
[b]
[indent]
protected int maxIndex(int size, int length) {
return size - length;
[/indent]}
[/b]
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:
- PagedTable.java – the modified implementation (notice that
maxIndex()
is overridden)
- PageChangeListener.java – separated out from PagedTable.java so it could be called from the filter
- 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.
12258.java (14.4 KB)
12259.java (400 Bytes)
12260.java (2.26 KB)