我正在使用SimplePager,我希望每页显示12个项目(用户).我的整个数据集是20个项目.
问题是第一页(正确)显示项目1-12,但第二页显示项目9-20.我希望第二页显示项目13-20.
出了什么问题?
这是我的代码:
CellTable<User> cellTable = new CellTable<User>();
SimplePager pager = new SimplePager(TextLocation.CENTER);
pager.setDisplay(cellTable);
pager.setPageSize(12);
ListDataProvider<User> dataProvider = new ListDataProvider<User>();<br>
dataProvider.setList(USERSList);
dataProvider.addDataDisplay(cellTable);
Run Code Online (Sandbox Code Playgroud)
先感谢您!
Sim*_* LG 11
设置
setRangeLimited(false)
Run Code Online (Sandbox Code Playgroud)
将始终显示下一页.
相反,我有rangeLimited为true,我已经覆盖了以下方法:
@Override
public void setPageStart(int index) {
if (getDisplay() != null) {
Range range = getDisplay().getVisibleRange();
int pageSize = range.getLength();
// Removed the min to show fixed ranges
//if (isRangeLimited && display.isRowCountExact()) {
// index = Math.min(index, display.getRowCount() - pageSize);
//}
index = Math.max(0, index);
if (index != range.getStart()) {
getDisplay().setVisibleRange(index, pageSize);
}
}
}
Run Code Online (Sandbox Code Playgroud)
@fbfcn和@MasterUZ的解决方案有效,只需稍加修改即可使其符合GWT 2.4的SimplePager:
public class MySimplePager extends SimplePager {
public MySimplePager() {
this.setRangeLimited(true);
}
public MySimplePager(TextLocation location, Resources resources, boolean showFastForwardButton, int fastForwardRows, boolean showLastPageButton) {
super(location, resources, showFastForwardButton, fastForwardRows, showLastPageButton);
this.setRangeLimited(true);
}
public void setPageStart(int index) {
if (this.getDisplay() != null) {
Range range = getDisplay().getVisibleRange();
int pageSize = range.getLength();
if (!isRangeLimited() && getDisplay().isRowCountExact()) {
index = Math.min(index, getDisplay().getRowCount() - pageSize);
}
index = Math.max(0, index);
if (index != range.getStart()) {
getDisplay().setVisibleRange(index, pageSize);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)