【问题标题】:GWT SimplePager LastButton issueGWT SimplePager LastButton 问题
【发布时间】:2012-04-06 18:15:47
【问题描述】:

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

我通过扩展 SimplePager 来使用 CustomerPager。

在第一次尝试中,单元表中显示 1+10 条记录:下一页和最后一页按钮已启用(第一页和上一页按钮已禁用),这是正确的。 但是 LastPage 按钮不起作用... :( 不知道是什么问题...(事件未触发)

奇怪的行为:

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

@2 假设我在第一页 n 我移动到第二页(单元格表中总共 3 页)。那时所有按钮都已启用,这是正确的。 在这种情况下,最后一个按钮正在工作,但行为类似于下一个按钮

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

可能是 AbstractPager 的 setPage(int index) 方法中的索引值不正确

Last按钮的代码流程如下

//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 可能有问题:|

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

我该如何解决这个问题?

【问题讨论】:

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

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


【解决方案1】:

如果没有看到更多代码,这是一个很难回答的问题,因为可能有多个地方出了问题。

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

如果您无法在开发模式下运行,我建议您在浏览器中设置一些 GWT 日志记录(将日志写入弹出面板或其他东西,例如 see this discussion)。

【讨论】:

    【解决方案2】:

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

    像这样调用下面的构造函数,看看你的问题解决了:

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

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

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

    您可以像这样调用表格的 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 方法(用法相同)。

    【讨论】:

    • [“寻呼机的默认构造函数没有给你一个“最后一个”按钮,而是一个“快进 1000 行”按钮(可怕,对吧?)”] 是的,这真的很可怕.我刚刚吹了一个下午。
    • 另外,请注意这个构造函数:SimplePager(SimplePager.TextLocation location, boolean showFastForwardButton, boolean showLastPageButton)
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

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

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

      【讨论】:

        猜你喜欢
        • 2017-06-15
        • 1970-01-01
        • 1970-01-01
        • 2012-02-21
        • 1970-01-01
        • 1970-01-01
        • 2011-10-15
        • 1970-01-01
        • 2011-05-11
        相关资源
        最近更新 更多