2011-05-19 8 views
12

Estoy usando SimplePager y quiero mostrar 12 elementos (usuarios) por página. Mi conjunto de datos completo es de 20 elementos.El conteo de filas de SimplePager funciona incorrectamente

El problema es que la primera página (correctamente) muestra los elementos del 1 al 12, pero la segunda página muestra los elementos del 9 al 20. Quiero que la segunda página muestre los elementos 13-20.

¿Qué está pasando?

Aquí está mi código:

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

gracias de antemano!

Respuesta

7
+0

Muchas gracias !!! Eso resolvió el problema ... Gracias ... –

+1

bueno, pero el truco para deshabilitar el interminable error "hasnextpage" no funciona, ¿qué te parece? –

+0

@ Fabio, la solución a continuación funciona y supera el número de página de hasne – Neil

11

Configuración

setRangeLimited(false) 

siempre mostrar una página siguiente.

En cambio, he rangeLimited en verdad y he anulado el siguiente método para esto:

@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

¡Esto funciona para mí! Muchas gracias – Neil

7

@fbfcn y @ solución de MasterUZ obras, con algunas ligeras modificaciones para que cumpla con GWT 2.4's 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

¡ESTE! Funciona perfecto con GWT 2.5.1 –

+0

funciona! Gracias :) – Ramanathan

Cuestiones relacionadas