ExtremeTable在大量记录造成大数分页时没有很好的解决页面的快速跳转,这是较遗憾的一个缺陷。最近因项目用到ExtremeTable,所以我就简单的添加了这个功能,当因为时间关系,并没有深入的完善。这里我先将我的代码贴出来,希望后续有人能继续完善。
1.org.extremecomponents.table.view.html.ToolbarBuilder 中加入如下方法。
public void pageJumpDroplist(){
Integer total = new Integer(model.getLimit().getTotalRows());
Integer from = new Integer(model.getLimit().getRowStart() + 1);
Integer to = new Integer(model.getLimit().getRowEnd());
Integer current = new Integer(model.getLimit().getCurrentRowsDisplayed());
Integer totalPage = (Integer)total/current;
if(total%current!=0)
totalPage=totalPage+1;
int currentPage = model.getLimit().getPage();
html.select().name(model.getTableHandler().prefixWithTableId() + TableConstants.DROWDOWNLIST_PAGE);
StringBuffer onchange = new StringBuffer();
onchange.append(new TableActions(model).getPageJumpAction());
html.onchange(onchange.toString());
html.close();
html.newline();
html.tabs(4);
for(int i=1;i<=totalPage;i++){
html.option().value("" + i);
if (currentPage == i) {
html.selected();
}
html.close();
html.append(String.valueOf(i));
html.optionEnd();
}
}
2.org.extremecomponents.table.view.html.TableActions 中加入
public String getPageJumpAction(){
StringBuffer action = new StringBuffer("javascript:");
action.append(getClearedExportTableIdParameters());
action.append(getPageJumpFormParameter(TableConstants.PAGE));
action.append(getOnInvokeAction());
return action.toString();
}
protected String getPageJumpFormParameter(String name) {
StringBuffer result = new StringBuffer();
String form = BuilderUtils.getForm(model);
String selectedOption = "this.options[this.selectedIndex].value";
result.append("document.forms.").append(form).append(".");
result.append(model.getTableHandler().prefixWithTableId()).append(name);
result.append(".value=").append(selectedOption).append(";");
return result.toString();
}
3.org.extremecomponents.table.view.DefaultToolbar 中你想要放置页面跳转下拉框的地方加入如下代码
html.td(4).close();
toolbarBuilder.pageJumpDroplist();
html.tdEnd();
我将我加的地方贴整个方法贴出来(红色是有修改的地方)
protected void columnRight(HtmlBuilder html, TableModel model) {
boolean showPagination = BuilderUtils.showPagination(model);
boolean showExports = BuilderUtils.showExports(model);
ToolbarBuilder toolbarBuilder = new ToolbarBuilder(html, model);
html.td(2).align("right").close();
html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(BuilderConstants.TOOLBAR_CSS).close();
html.tr(3).close();
if (showPagination) {
html.td(4).close();
toolbarBuilder.firstPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.prevPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.nextPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.lastPageItemAsImage();
html.tdEnd();
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
html.td(4).close();
toolbarBuilder.pageJumpDroplist();
html.tdEnd();
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
html.td(4).style("width:20px").close();
html.newline();
html.tabs(4);
toolbarBuilder.rowsDisplayedDroplist();
html.img();
html.src(BuilderUtils.getImage(model, BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));
html.style("border:0");
html.alt("Rows Displayed");
html.xclose();
html.tdEnd();
if (showExports) {
html.td(4).close();
toolbarBuilder.separator();
html.tdEnd();
}
}
if (showExports) {
Iterator iterator = model.getExportHandler().getExports().iterator();
for (Iterator iter = iterator; iter.hasNext();) {
html.td(4).close();
Export export = (Export) iter.next();
toolbarBuilder.exportItemAsImage(export);
html.tdEnd();
}
}
html.trEnd(3);
html.tableEnd(2);
html.newline();
html.tabs(2);
html.tdEnd();
}
4.org.extremecomponents.table.core.TableConstants中加入一行
public final static String DROWDOWNLIST_PAGE= "dp";
5.编译打包,ok,搞定了。下周我会把我的jar传上来。
就这样,不是很难,ExtremeTable是个不错的东东,希望大家一起来完善。