Подтвердить что ты не робот

Счетчик строк SimplePager работает неправильно

Я использую 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);

Заранее благодарю вас!

4b9b3361

Ответ 2

Настройка

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

Ответ 3

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

Ответ 4

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