问题
The cell table pagination is behaving weirdly. check the example from GWT http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable
The page size here is defined as 15. This is the problem-
- click on last page button. Results for 241 to 250 are shown.
- Now click on previous button - results from 226-240 are shown.
- Now click on next button ( this is where the problem is). It showns results from 236 to 250. Whereas it should have displyed 241-250.
I am having same issue in my project. Is there any fix for this ??
回答1:
This is a known, reported bug. As mentioned in that bug report, there is a workaround:
As workaround, one can subclass SimplePager in order to override this behaviour defined in method setPageStart:
@Override public void setPageStart(int index) { if (this.getDisplay() != null) { Range range = this.getDisplay().getVisibleRange(); int pageSize = range.getLength(); // if (isRangeLimited && display.isRowCountExact()) { // index = Math.min(index, display.getRowCount() - pageSize); // } index = Math.max(0, index); if (index != range.getStart()) { this.getDisplay().setVisibleRange(index, pageSize); } } }
回答2:
When you make the pager initialization you must set:
pager.setRangeLimited(false);
This method sets whether or not the page range should be limited to the actual data size.
If true, all operations will adjust so that there is always data visible on the page.
回答3:
The problem was, CellTable class was designed to accommodate the data as per given page size. and hence the problem. I was expecting this might be fixed in GWT 2.4 release. You can log this problem in GWT website and let's hope this be fixed in next release.
@
回答4:
Override the hasNextPage() like below.
pager = new SimplePager(TextLocation.CENTER,(SimplePager.Resources) GWT.create(Resources.class), false,10, true){
@Override
public boolean hasNextPage() {
if(this.getPage()<(this.getPageCount()-1)) {
return true;
}
return false;
}
};
回答5:
Create subclass of simplepager like this with nextPage method.
public class CustomSimplePager extends SimplePager {
@Override
public void nextPage() {
// TODO Auto-generated method stub
HasRows display = getDisplay();
if (display != null) {
Range range = display.getVisibleRange();
if (hasNextPage())
setPageStart(range.getStart() + range.getLength());
}
}
}
And set pager.setRangeLimited(false);
来源:https://stackoverflow.com/questions/8391646/gwt-celltable-with-simple-pager-issue