Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimplePager row count is working incorrectly

Tags:

gwt

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!

like image 830
Maria Papadopoulou Avatar asked May 19 '11 10:05

Maria Papadopoulou


2 Answers

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);
            }
        }
    }
}
like image 128
MasterUZ Avatar answered Oct 20 '22 06:10

MasterUZ


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);
    }
  }
}
like image 21
Simon LG Avatar answered Oct 20 '22 06:10

Simon LG