GWT Simple Pager Help

I am stuck with a gwt cell pager that I want to bind to a cell table. I configure it as follows:

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

Correctly Defined ColumnM

But when the cell table is displayed, the first three rows are displayed correctly, but when I click next, the rows are not displayed, and the cell table is as if they were loaded. Now from this page, if I click back, again the page will look as if it was loaded.

Now another problem is that I can continuously click further, and the number of pages continues to be added, even if there are only 8 lines

+7
source share
4 answers

I ran into this problem when I first tried using the cell table for swap. It is implemented in such a way that the pager does not make any assumptions about your data set even after calling setRowSize. This is archived 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 when the pager continues. Now, to implement paging, you will also need to add a RangeChangeHandler to the cell table for setting data. Here is a 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); } 
+14
source

It may be easier to use ListDataProvider<T> rather than just providing a list. So your example:

 // 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); 
+4
source

I had the same problem, and I needed to set the page size of cellTable and remove the page size of the pager as follows:

 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); // set the PageSize of the cellTable cellTable.setPageSize(3); 
+3
source

Here is my test with GWT 2.5 - I am using AsyncDataProvider:

 SimplePager sp = new SimplePager(TextLocation.LEFT, true, 2 * ct.getPageSize(), true); AsyncDataProvider<Menu> adp = new AsyncDataProvider<Menu>() { @Override protected void onRangeChanged(HasData<Menu> display) { final Range range = display.getVisibleRange(); ColumnSortInfo csi = ct.getColumnSortList().get(0); String dataStoreName = csi.getColumn().getDataStoreName(); boolean isAscending = csi.isAscending(); AAFcms.getAAFService().getAdminMenu( new AdminMenuReq(range, dataStoreName, isAscending), new AsyncCallback<AdminMenuResp>() { @Override public void onFailure(Throwable caught) { System.out.println(caught.getStackTrace()); // TODO Auto-generated method stub } @Override public void onSuccess(AdminMenuResp result) { ct.setRowData(range.getStart(), result.getMenus()); ct.setRowCount(result.getRows(), true); } }); } }; 
-one
source

All Articles