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是個不錯的東東,希望大家一起來完善。