GWT SimplePager LastButton问题

时间:2012-03-22 07:22:17

标签: gwt pager gwt-2.2-celltable gwt-celltable

我遇到了SimplePager的lastButton问题。 我在celltable中有3页,页面大小= 11(1个空记录+10个记录(有值)),总记录= 26。

我通过扩展SimplePager使用了CustomerPager。

在第一次尝试中,在Celltable中显示1 + 10条记录:Next&启用最后一页按钮(禁用第一个&上一个按钮),这是正确的。 但LastPage按钮无法正常工作... :(不知道问题是什么......(事件不会触发)

奇怪的行为:

@ 1最后一页按钮仅在我访问最后一页时才有效(在我的情况下为3页)。

@ 2假设我在第1页n移动到第2页(在celltable中共3页)。那个时候所有按钮都启用了,这是正确的。 在这种情况下,“上一步”按钮正在运行,但其行为类似于“下一步按钮”

我的GWT应用程序已集成到我们的某个产品中,因此无法从客户端进行调试。

可能是AbstractPager

中setPage(int index)方法中的索引值不正确

最后一个按钮的代码流程如下

//From SimplePager

lastPage.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
          lastPage();
        }
      });


       @Override
  public void lastPage() {
    super.lastPage();
  }

 // From AbstractPager
  /**
   * Go to the last page.
   */
  protected void lastPage() {
    setPage(getPageCount() - 1);
  }
 protected void setPage(int index) {
    if (display != null && (!isRangeLimited || !display.isRowCountExact() || hasPage(index))) {
      // We don't use the local version of setPageStart because it would
      // constrain the index, but the user probably wants to use absolute page
      // indexes.
      int pageSize = getPageSize();
      display.setVisibleRange(pageSize * index, pageSize);
    }
  }

或者可能是某些条件错误来自上面的代码(来自setPage())

实际记录= 26和3空记录(第1空记录/页)

可能是dataSize的问题:|

如何根据数据大小检查页数? ?

我该如何解决这个问题?

4 个答案:

答案 0 :(得分:3)

编辑我发现寻呼机的默认构造函数没有给你一个“最后”按钮,而是一个“快进1000行”按钮(可怕,对吧?)。

调用以下构造函数,并查看问题已解决:

SimplePager.Resources resources = GWT.create(SimplePager.Resources.class); SimplePager simplePager = new SimplePager(TextLocation.CENTER, resources , false, 1000, true);

第一个“false”标志关闭“fastforward”按钮,最后一个“true”标志打开“last”按钮。

只有当寻呼机知道您拥有的记录总数时,最后一个按钮才会起作用。

您可以调用表的setRowCount函数来更新总数,如下所示:

int totalRecordsSize = 26; //the total amount of records you have boolean isTotalExact = true; //is it an estimate or an exact match table.setRowCount(totalRecordsSize , isTotalExact); //sets the table's total and updates the pager (assuming you called pager.setDisplay(table) before)

如果您正在使用附加的DataProvider,而不是所有的updateRowCount方法(相同用法)。

答案 1 :(得分:0)

在没有看到更多代码的情况下,这是一个难以回答的问题,因为可能有多个地方出现问题。

我会确保您在SimplePager上调用setDisplay(...),以便它拥有所需的数据来计算其范围。

如果您无法在devmode中运行,我建议在浏览器中设置一些GWT日志记录(将日志写入弹出式面板或其他内容,see this discussion以获取示例)。

答案 2 :(得分:0)

我认为问题与setPage()中的条件有关。尝试在if条件之前放置SOP或调试代码

答案 3 :(得分:0)

仅在OnRange更改方法AsyncDataProvider中添加了cellTable.setRowCount(int size, boolean isExact)我的问题已解决:)

protected void onRangeChanged(HasData<RecordVO> display) {
//----- Some code --------
cellTable.setRowCount(searchRecordCount, false);
//----- Some code --------
}
相关问题