Child pages
  • Refresh ListGrid Periodically (Smart GWT)
Skip to end of metadata
Go to start of metadata


ListGrid displays a list of objects in a grid, where each row represents one object and each cell in the row represents one property.

Periodically updating a ListGrid is possible in the following ways:

  • Using the invalidateCache method. This approach updates the data and will show a loading message. However, this API will disrupt the existing view.
  • Transparent update by DataSource using the fetchData method. This method updates the data but doesn't show a loading message and won't disrupt the existing view.

A working example is available in the attachment.

Transparent update

For transparent loading of the data the fetchData method should be used.

Update by DataSource
private void onRefresh() {
    DataSource dataSource = listGrid.getDataSource();
    Criteria criteria = listGrid.getCriteria();
    Integer[] visibleRows = listGrid.getVisibleRows();
	// request one page's worth of data on either side of the current viewport
    Integer startRow = visibleRows[0] - listGrid.getResultSet().getResultSize();
    Integer endRow = visibleRows[1] + listGrid.getResultSet().getResultSize();
    if (startRow < 0) {
        startRow = 0;
	DSRequest request = new DSRequest();
	dataSource.fetchData(criteria, new DSCallback() {
        public void execute(DSResponse response, Object rawData, DSRequest request) {
    }, request);

private void onRefreshed(DSResponse response) {
	DataSource dataSource = listGrid.getDataSource();
    ResultSet resultSet = new ResultSet(dataSource);
	// correctly position the result in the resultset's cache 
    Record[] result = response.getData();
    Record[] initialData = new Record[response.getTotalRows()];
    System.arraycopy(result, 0, initialData, response.getStartRow(), result.length);


  File Modified
ZIP Archive Jun 11, 2014 by Bill Bruyn

  • No labels