Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Description

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

Periodical updating ListGrid is possible in the following ways:

  • Use invalidateCache method. It update the data will show a loading message and will disrupt the existing view.
  • Transparent update by DataSource using fetchData method. It update the data will not show a loading message and will not disrupt the existing view.

Transparent update

For transparent loading the data should be used fetchData method.

Update by DataSource
final com.smartgwt.client.data.DataSource dataSource = listGrid.getDataSource();
com.smartgwt.client.data.Criteria criteria = listGrid.getCriteria();
dataSource.fetchData(criteria, new com.smartgwt.client.data.DSCallback() {
    @Override
    public void execute(com.smartgwt.client.data.DSResponse response, Object rawData, com.smartgwt.client.data.DSRequest request) {
        com.smartgwt.client.data.ResultSet resultSet = new com.smartgwt.client.data.ResultSet(dataSource);
        resultSet.setInitialLength(response.getTotalRows());
        resultSet.setInitialData(response.getData());
        listGrid.setData(resultSet);
    }
});

Transparent update range

For transparent loading the data range should be used DSRequest. It allows you to specify a range of data to load.

Update by DataSource
final com.smartgwt.client.data.DataSource dataSource = listGrid.getDataSource();
com.smartgwt.client.data.Criteria criteria criteria = listGrid.getCriteria();
Integer[] visibleRows = listGrid.getVisibleRows();
Integer startRow = visibleRows[0];
Integer endRow = visibleRows[1];
com.smartgwt.client.data.DSRequest request = new com.smartgwt.client.data.DSRequest();
int preloadSize = 10;
request.setStartRow(((startRow - preloadSize) < 0) ? 0 : (startRow - preloadSize));
request.setEndRow(endRow + preloadSize);
dataSource.fetchData(criteria, new com.smartgwt.client.data.DSCallback() {
    @Override
    public void execute(com.smartgwt.client.data.DSResponse response, Object rawData, com.smartgwt.client.data.DSRequest request) {
        com.smartgwt.client.data.ResultSet resultSet = new com.smartgwt.client.data.ResultSet(dataSource);
        resultSet.setInitialLength(response.getTotalRows());
        com.smartgwt.client.data.Record[] records;
        if (response.getStartRow() == 0) {
            records = response.getData();
        } else {
            records = new com.smartgwt.client.data.Record[response.getTotalRows()];
            System.arraycopy(response.getData(), 0, records, response.getStartRow(), response.getData().length);
        }
        resultSet.setInitialData(records);
        listGrid.setData(resultSet);
    }
}, request);
  • No labels