GWT - celltable with simple pager issue

帅比萌擦擦* 提交于 2019-12-23 10:25:14

问题


The cell table pagination is behaving weirdly. check the example from GWT http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable

The page size here is defined as 15. This is the problem-

  1. click on last page button. Results for 241 to 250 are shown.
  2. Now click on previous button - results from 226-240 are shown.
  3. Now click on next button ( this is where the problem is). It showns results from 236 to 250. Whereas it should have displyed 241-250.

I am having same issue in my project. Is there any fix for this ??


回答1:


This is a known, reported bug. As mentioned in that bug report, there is a workaround:

As workaround, one can subclass SimplePager in order to override this behaviour defined in method setPageStart:

@Override
public void setPageStart(int index) {
    if (this.getDisplay() != null) {
        Range range = this.getDisplay().getVisibleRange();
        int pageSize = range.getLength();
//      if (isRangeLimited && display.isRowCountExact()) {
//          index = Math.min(index, display.getRowCount() - pageSize);
//      }
        index = Math.max(0, index);
        if (index != range.getStart()) {
            this.getDisplay().setVisibleRange(index, pageSize);
        }
    }
}



回答2:


When you make the pager initialization you must set:

pager.setRangeLimited(false);

This method sets whether or not the page range should be limited to the actual data size.

If true, all operations will adjust so that there is always data visible on the page.




回答3:


The problem was, CellTable class was designed to accommodate the data as per given page size. and hence the problem. I was expecting this might be fixed in GWT 2.4 release. You can log this problem in GWT website and let's hope this be fixed in next release.

@




回答4:


Override the hasNextPage() like below.

pager = new SimplePager(TextLocation.CENTER,(SimplePager.Resources) GWT.create(Resources.class), false,10, true){
                    @Override
                    public boolean hasNextPage() {
                        if(this.getPage()<(this.getPageCount()-1)) {
                            return true;
                        }
                        return false;
                    }
                };



回答5:


Create subclass of simplepager like this with nextPage method.

public class CustomSimplePager extends SimplePager {

     @Override
     public void nextPage() {
           // TODO Auto-generated method stub
           HasRows display = getDisplay();
           if (display != null) {
           Range range = display.getVisibleRange();
                if (hasNextPage())
                      setPageStart(range.getStart() + range.getLength());
           }
     }
 }

And set pager.setRangeLimited(false);



来源:https://stackoverflow.com/questions/8391646/gwt-celltable-with-simple-pager-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!