I implemented a data view that has a column for sorting data similar to wicket example. However I started testing it and it turned out that pageable navigation didn’t work. I started debugging and found out that it works (you can page through) with a simple ListDataProvider implementation however it doesn’t work with SortableDataProvider. I almost went to the forum to ask a question, when i noticed this little caveat. It is required to implement iterator() method in SortableDataProvider, meanwhile it is NOT required to do so in ListDataProvider. And it turns out there is a reason for it.
Because list implementation is not sortable, list view for any page will not change. That means you can click page 1 and get items (a,d,e,b,c). Then you can click page 2 and you can get items (f,h,g,j,i). And so on…
However if you have a sortable list that is also pageable if you sort the list, the contents must change:
it should be
page1 – (a,b,c,d,e)
page2 – (f,g,h,i,j)
Because of that the iterator stub has 2 arguments (first, count). First is the first element on the page, and count how many records are on the page. Therefore, if you want to sort the whole list, but return only the data relevant to the page you are on, you should do
public Iterator iterator(int first, int count) {
.
.
.
Collections.sort (list, new LetterComparator())
.
.
.
return list.sublist(first, first + count).iterator;
}