2011-05-19 49 views
12

我使用的是SimplePager,我想每頁顯示12項(用戶)。我的整個數據集是20個項目。SimplePager行數不正確

問題是第一頁(正確)顯示項目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); 

預先感謝您!

回答

7
+0

非常感謝!這解決了這個問題...謝謝... – 2011-05-20 08:12:44

+1

不錯,但禁用無盡的「hasnextpage」錯誤的伎倆不起作用,你認爲? – 2011-08-19 20:45:59

+0

@Fabio,下面的解決方案可以解決問題,並解決了原有的問題 – Neil 2012-09-02 12:01:42

11

設置

setRangeLimited(false) 

將始終顯示下一頁。

相反,我在真正有rangeLimited,我已經覆蓋了以下方法是:

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

這對我有用!非常感謝 – Neil 2012-09-02 11:57:53

7

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

這一個!與GWT 2.5.1作品完美搭配 – 2014-02-08 23:31:22

+0

作品!謝謝 :) – Ramanathan 2014-06-25 04:44:57