GWT DataGrid setLoadingIndicator无效

时间:2012-03-01 20:34:55

标签: gwt datagrid

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

我没有找到任何资源。对此的支持非常差。

我使用以下方式使用DataGrid:

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

在程序流程中我使用:

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

当我想将DataGrid置于'LOADING'状态时,即在进行RPC调用之前,然后:

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

在网格填充数据之后。

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

请帮忙。

3 个答案:

答案 0 :(得分:9)

如果您致电updateRowCount(0, false),将会显示加载图片。

答案 1 :(得分:1)

我的应用程序中有几个DataGrids,我使用下面的代码片段来表示所有这些。您必须首先清除数据,以便网格中没有记录,然后将行计数设置为大于零的数字。 请注意,加载指示器仅在通过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);

答案 2 :(得分:0)

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