Trouble with CellList empty widget and AsyncDataProvider

落花浮王杯 提交于 2019-12-11 09:48:16

问题


I have a CellList that I'm populating with an AsyncDataProvider:

  @UiField(provided = true)
  CellList<PlayerDataEntity> friendCellList;


  @Inject
  FriendListViewImpl(FriendListController controller) {
    friendCellList = new CellList<PlayerDataEntity>(new PlayerCell());

    initWidget(uiBinder.createAndBindUi(this));

    // if we don't set the row data to empty before trying to get the real data,
    // the empty list widget will never appear. But if we do set this, 
    // then the real data won't show up. 
    friendCellList.setRowData(Lists.<PlayerDataEntity>newArrayList());

      new AsyncDataProvider<PlayerDataEntity>() {
        @Override
        protected void onRangeChanged(final HasData<PlayerDataEntity> display) {
          rpcService.getPlayers(new AsyncCallback<List<PlayerDataEntity>>() {
              @Override
              public void onSuccess(List<PlayerDataEntity> result) {
                 display.setRowData(0, result);
              }
            });
      }
    }.addDataDisplay(friendCellList);

    friendCellList.setEmptyListWidget(new Label("No friends found"));
  }

If I don't initially set the row data to an empty list, then the empty list widget won't show up if the RPC service returns an empty list. However, if I do initially set the row data to the an empty list, and the RPC returns a non-empty list, that data won't show up in the widget.

I must be misunderstanding some aspect of the CellList's API. What am I doing wrong?


回答1:


If you know, that the total list (not just the list in the range) is empty, then you can set display.setRowCount(0), so the CellList will display "No friends found".

If your service always returns the entire list, this can be done easily like

public void onSuccess(List<PlayerDataEntity> result) {
  display.setRowCount(result.size());
  display.setRowData(0, result);
}



回答2:


Add the following line to the method:

@Override
public void onSuccess(List<PlayerDataEntity> result) {
   display.setRowData(0, result);
   ((CellList<PlayerDataEntity>) display).redraw();
}


来源:https://stackoverflow.com/questions/10566483/trouble-with-celllist-empty-widget-and-asyncdataprovider

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!