5

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 ??

ravi
  • 1,707
  • 4
  • 29
  • 44

5 Answers5

12

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);
        }
    }
}
Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94
8

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.

Msonic
  • 1,456
  • 15
  • 25
Nicolas Finelli
  • 2,170
  • 1
  • 14
  • 9
  • I almost got crazy with last page problems. This should come disabled by default. – Federico Pugnali Feb 08 '14 at 23:18
  • The problem with this is the infinite next page problem. See a better solution reading Neil answer at http://stackoverflow.com/questions/6057141/simplepager-row-count-is-working-incorrectly – Federico Pugnali Feb 08 '14 at 23:30
1

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;
                    }
                };
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Mari
  • 11
  • 1
1

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.

@

Ashok
  • 1,902
  • 3
  • 22
  • 30
  • 1
    As mentioned in my answer, it has already been reported: http://code.google.com/p/google-web-toolkit/issues/detail?id=6163 – Chris Cashwell Dec 05 '11 at 21:32
0

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

Hideme Sri
  • 193
  • 9