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 Periodically updating a ListGrid is possible in the following ways:
- Use Using the invalidateCache method. It update This approach updates the data and will show a loading message and . However, this API will disrupt the existing view.
- Transparent update by DataSource using the fetchData method. It update This method updates the data will not but doesn't show a loading message and will not won't disrupt the existing view.
Info |
---|
A working example is available in the attachment. |
Transparent update
For transparent loading of the data the fetchData method should be used fetchData method.
Code Block |
---|
language | java |
---|
title | Update by DataSource |
---|
linenumbers |
---|
|
final com.smartgwt.client.data. |
private void onRefresh() {
DataSource dataSource = listGrid.getDataSource();
com.smartgwt.client.data.
Criteria criteria = listGrid.getCriteria();
dataSource.fetchData(criteria, new com.smartgwt.client.data.DSCallback() { Integer[] visibleRows = listGrid.getVisibleRows();
@Override
// publicrequest 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())one page's worth of data on either side of the current viewport
Integer startRow = visibleRows[0] - listGrid.getResultSet().getResultSize();
Integer endRow = visibleRows[1] + resultSetlistGrid.setInitialDatagetResultSet(response).getDatagetResultSize());
if (startRow listGrid.setData(resultSet);
< 0) {
} }); |
Transparent update range
For transparent loading the data range should be used DSRequest. It allows you to specify a range of data to load.
Code Block |
---|
title | Update by DataSource |
---|
|
final com.smartgwt.client.data.DataSource dataSource startRow = listGrid.getDataSource()0;
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) < 0request.setEndRow(endRow);
? 0 : (startRow - preloadSizerequest.setSortBy(listGrid.getSort());
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 onRefreshed(response);
resultSet.setInitialLength(response.getTotalRows());}
}, request);
}
com.smartgwt.client.data.Record[] records;
private void onRefreshed(DSResponse response) {
DataSource dataSource if= (responselistGrid.getStartRowgetDataSource();
== 0) { ResultSet resultSet = new ResultSet(dataSource);
records = resultSet.setInitialLength(response.getDatagetTotalRows());
// correctly position the result } else {in the resultset's cache
Record[] result = response.getData();
recordsRecord[] initialData = new com.smartgwt.client.data.Record[response.getTotalRows()];
System.arraycopy(response.getData()result, 0, recordsinitialData, response.getStartRow(), responseresult.getData().length);
resultSet.setInitialData(initialData);
}
resultSet.setInitialSort(listGrid.getSort());
resultSet.setInitialData(records);
resultSet.setCriteria(listGrid.getCriteria());
listGrid.setData(resultSet);
}
}, request);
|
Attachments