I'm trying to use the feature of GWT DataGrid to show an animated gif when data is loading from a RPC call to the server.
I didn't find any resource whatsoever anywehere. The support for this is really poor.
I inizialize my DataGrid using:
myDataGrid.setLoadingIndicator(new Image(/*my ImageResource object*/);
and during the flow of the program I use:
myDataGrid.fireEvent(new LoadingStateChangeEvent(LoadingState.LOADING));
when I want to put the DataGrid in the 'LOADING' state, i.e. just before making an RPC call, and then:
myDataGrid.fireEvent(new LoadingStateChangeEvent(LoadingState.LOADED));
just after the grid has been populated with data.
This doesn't work. I do not see any change in the DataGrid, I can't see the animated gif, it just remains unchanged during the process. Is there something I'm doing wrong?
Please help.
If you call updateRowCount(0, false)
, the loading image will be displayed.
I have several DataGrids in my application and I use the code-snippet below for all of them. You have to clear the data first, so that there are zero records in the grid, and then set the row-count to a number greater than zero. Please note that the loading indicator is only animated while data is received via RPC. As soon as the grid is rendered (which may also take a while) the animation freezes.
// 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With