SimplePager 行计数工作不正常

发布于 2024-11-08 06:37:29 字数 557 浏览 0 评论 0 原文

我正在使用 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);

提前谢谢您!

I'm using SimplePager and I want to show 12 items (users) per page. My entire data set is 20 items.

The problem is that the first page (correctly) shows items 1-12, but the second page shows items 9-20. I want the second page to show items 13-20.

What's going wrong?

Here is my code:

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);

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

就像说晚安 2024-11-15 06:37:30

设置

setRangeLimited(false)

将始终显示下一页。

相反,我将 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);
    }
  }
}

Setting

setRangeLimited(false)

will always show a next page.

Instead, I have rangeLimited at true and I've overridden the following method for this :

@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);
    }
  }
}
巾帼英雄 2024-11-15 06:37:30

@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);
          }
        }  
      }
    }

@fbfcn and @MasterUZ's solution works, with a few slight modifications to make it comply with GWT 2.4's 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);
          }
        }  
      }
    }
哥,最终变帅啦 2024-11-15 06:37:30
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.view.client.Range;

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);
    }

    @Override
    public void setPageStart(int index) {
        if (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);
            }
        }
    }
}
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.view.client.Range;

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);
    }

    @Override
    public void setPageStart(int index) {
        if (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);
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文