java GWT 简单寻呼机帮助

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4604489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:10:24  来源:igfitidea点击:

GWT Simple Pager Help

javagwtwidgetcell

提问by Noor

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

我被我想附加到单元格表的 gwt 单元格寻呼机卡住了。我是这样设置的:

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

ColumnM 已正确定义

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

现在,另一个问题是我可以连续按下一步,即使只有8行,页数也会不断增加

回答by LINEMAN78

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.

当我第一次尝试使用单元格表进行分页时,我遇到了同样的问题。它以这样一种方式实现,即使在您调用 setRowSize 之后,寻呼机也不会对您的数据集做出任何假设。这是以这种方式构建的,以便您可以执行延迟加载。

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:

一旦您知道有多少行数据可用,您需要调用cellTable.setRowCount(int),这将解决寻呼机继续运行的问题。现在,要实现分页,您还需要向单元格表添加 RangeChangeHandler 以设置数据。下面是一些示例代码:

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

回答by mhaligowski

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

使用 可能更容易ListDataProvider<T>,而不仅仅是提供列表。所以,你的例子是:

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

回答by Van Hoof

I faced the same problem, and I only had to set the page size of the cellTable and remove the page size of the pager like this :

我遇到了同样的问题,我只需要设置 cellTable 的页面大小并删除寻呼机的页面大小,如下所示:

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

回答by AAF

Here my test with GWT 2.5 - i use AsyncDataProvider:

这是我使用 GWT 2.5 进行的测试 - 我使用 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);
                        }
                    });
        }
    };