【问题标题】:GWT DataGrid setLoadingIndicator has no effectGWT DataGrid setLoadingIndicator 没有效果
【发布时间】:2012-03-20 09:14:55
【问题描述】:

我正在尝试使用 GWT DataGrid 的功能在数据从 RPC 调用加载到服务器时显示动画 gif。

我在任何地方都没有找到任何资源。对这个的支持真的很差。

我使用以下方法初始化我的 DataGrid:

myDataGrid.setLoadingIndicator(new Image(/*my ImageResource object*/);

在我使用的程序流程中:

myDataGrid.fireEvent(new LoadingStateChangeEvent(LoadingState.LOADING));

当我想将 DataGrid 置于“加载”状态时,即在进行 RPC 调用之前,然后:

myDataGrid.fireEvent(new LoadingStateChangeEvent(LoadingState.LOADED));

就在网格填充数据之后。

这不起作用。我在 DataGrid 中看不到任何变化,我看不到动画 gif,它只是在此过程中保持不变。是不是我做错了什么?

请帮忙。

【问题讨论】:

  • 是的,我的意思是 RPC(远程过程调用)。是的,GWT 用于与服务器通信的标准方式。不要专注于此。问题是关于 DataGrid 的加载状态。如何设置 DataGrid 的“正在加载”状态,以便它显示我之前使用 setLoadingIndicator() 函数设置的加载指示器,然后如何设置 DataGrid 的正常“已加载”状态所以那是显示加载的行?这是真正的问题。我使用了 dataGrid.fireEvent(new LoadingStateChangeEvent(LOADING/LOADED));但它似乎没有效果。我哪里错了?

标签: gwt datagrid


【解决方案1】:

如果你调用updateRowCount(0, false),会显示加载图片。

【讨论】:

  • 感谢您的回复。无论如何,我找不到 DataGrid 的 updateRowCount() 方法。这个方法是指什么?
  • 事实上,我看到 updateRow() 是从 AbstractDataProvider 继承的并且受到保护,所以我不能调用它。为什么要保护它?还有其他方法吗?
  • 它受到保护,因为您的数据提供者应该调用它。因此,当您向数据提供者询问更多信息时,您的 DP 可以立即调用 updateRowCount(0, false),然后,当您的服务器调用返回时,调用 updateRowCount(sizeOfResult, true)
  • 我明白,但我的数据提供者不是 AsyncDataProvider 的子类,它只是一个简单的 ListDataProvider。我没有定义 MyDataProvider extends AsyncDataProvider {...} 但我只是有一个 ListDataProvider 所以我没有可能调用 updateRowCount()。事实上,我真的很简单需要把数据网格置于'Loading'的状态,真的有那么复杂吗?我想下一个版本应该会简化一些。
  • 您可以尝试dataProvider = new ListDataProvider<MyItem>() { public void updateRowCount(int rows, boolean b) { super.updateRowCount(rows, b);}} 我想,并从提供程序外部调用 updateRowCount。我认为 GWT 团队打算让显示的状态完全基于数据提供者,所以我不一定希望在下一个版本中出现外部命令。
【解决方案2】:

我的应用程序中有几个 DataGrid,我对所有这些都使用了下面的 code-sn-p。您必须先清除数据,使网格中的记录为零,然后将行数设置为大于零的数字。 请注意,加载指示器仅在通过 RPC 接收数据时才会显示动画。一旦网格被渲染(也可能需要一段时间),动画就会冻结。

    // Only required if you are using a pager
    int pageSize = pager.getPageSize();

    // This will trigger the onRangeChanged-event and call
    // the data provider
    dataGrid.setVisibleRangeAndClearData(new Range(0, 1), true);
    // Together with the row above, this will show the loading-indicator
    // in the data grid
    dataGrid.setRowCount(1);

    // Usually, the data is loaded when the data grid is initialized.
    // In my application, the user has to enter some input first and
    // then (re-)load the data via a button.
    // If you want your data grid to be filled when it is intialized,
    // simply remove the if-block
    if (dataProvider.getDataDisplays().size() == 0) {
        dataProvider.addDataDisplay(dataGrid);
    }

    // This will re-set the paging (only required if you are using a pager)
    dataGrid.setPageSize(pageSize);

【讨论】:

    【解决方案3】:

    我不确定它是在哪个版本中添加的,但在 2.8.0-beta1 中,我使用 dataGrid.setRowCount(0, false) 来实现类似的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 2018-05-21
      • 2018-07-28
      相关资源
      最近更新 更多