Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT Simple Pager Help

I am stuck with the gwt cell pager which I want to attach to a cell table. I am setting like this:

List <ForumMessage> AllMessages=populated from an rpc;
CellTable cellTable = new CellTable  <ForumMessage>();
simplePager = new SimplePager();
cellTable.addColumn(ColumnM);
cellTable.setRowData(0,AllMessages);
simplePager.setDisplay(cellTable);
simplePager.setPageSize(3);

ColumnM has correctly been defined

But when the cell table is being displayed, the first three rows are correctly shown but when i press next, no rows are shown and the cell table is as if loading. Now from that page, if I press back, again the page is as if loading.

Now, another problem is that I can continually press next and the numbers of pages keeps on adding even if there are only 8 rows

like image 286
Noor Avatar asked Jan 05 '11 13:01

Noor


2 Answers

I ran into this same problem when I first tried to use the cell table for paging. It is implemented in such a way that the pager makes no assumptions about your dataset even after you call setRowSize. This is architected this way so that you can perform lazy loading.

Once you know how many rows of data are available you need to call cellTable.setRowCount(int) and this will fix your problem where the pager keeps going. Now, to implement paging you will also need to add a RangeChangeHandler to the cell table to set the data. Here is some sample code:

@Override
public void onRangeChange(RangeChangeEvent event)
{
    Range range = cellTable.getVisibleRange();
    int start = range.getStart();
    int length = range.getLength();
    List<ForumMessage> toSet = new ArrayList<ForumMessage>(length);
    for (int i = start; i < start + length && i < AllMessages.size(); i++)
        toSet.add((ForumMessage) AllMessages.get(i));
    cellTable.setRowData(start, toSet);
}
like image 135
LINEMAN78 Avatar answered Oct 12 '22 21:10

LINEMAN78


It may be easier to use ListDataProvider<T>, instead of just providing the list. So, your example would be:

// get the list
List <ForumMessage> AllMessages=populated from an rpc;

// create table
CellTable cellTable = new CellTable  <ForumMessage>();
cellTable.addColumn(ColumnM);

// create pager
simplePager = new SimplePager();
simplePager.setDisplay(cellTable);
simplePager.setPageSize(3);

// create data provider
ListDataProvider<ForumMessage> dataProvider = new ListDataProvider<ForumMessage>();
dataProvider.addDataDisplay(cellTable);
dataProvider.setList(AllMessages);
like image 21
mhaligowski Avatar answered Oct 12 '22 22:10

mhaligowski