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.
...
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 | true |
---|
|
private void updateAllonRefresh() {
DataSource dataSource = listGrid.getDataSource();
Criteria criteria = listGrid.getCriteria();
dataSource.fetchData(criteria, createUpdateAllCallback() Integer[] visibleRows = listGrid.getVisibleRows();
} |
Code Block |
---|
title | Handle server response |
---|
|
private DSCallback createUpdateCallback() {
return new DSCallback() {
// request one page's worth of data on either side of the current viewport
@OverrideInteger startRow = visibleRows[0] - listGrid.getResultSet().getResultSize();
public voidInteger execute(DSResponse response, Object rawData, DSRequest request) {endRow = visibleRows[1] + listGrid.getResultSet().getResultSize();
if (startRow < 0) {
DataSource dataSource = listGrid.getDataSource(); startRow = 0;
}
DSRequest ResultSetrequest resultSet = new ResultSetDSRequest(dataSource);
request.setStartRow(startRow);
request.setEndRow(endRow);
resultSetrequest.setInitialLengthsetSortBy(responselistGrid.getTotalRowsgetSort());
dataSource.fetchData(criteria, new DSCallback() {
@Override
resultSet.setInitialData(response.getData());
public void execute(DSResponse response, Object rawData, DSRequest request) {
listGrid.setDataonRefreshed(resultSetresponse);
}
}, request);
}
|
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 |
---|
|
private void updateRangeonRefreshed(DSResponse response) {
DataSource dataSource = listGrid.getDataSource();
CriteriaResultSet criteriaresultSet = listGrid.getCriteria(new ResultSet(dataSource);
Integer[] visibleRows = listGrid.getVisibleRows(resultSet.setInitialLength(response.getTotalRows());
Integer startRow = 0;
// correctly position the result in the resultset's cache
Integer endRow = (visibleRowsRecord[1] result += listGrid.getResultSet().getResultSize()response.getData();
DSRequest requestRecord[] initialData = new DSRequestRecord[response.getTotalRows()];
request.setStartRow(startRowSystem.arraycopy(result, 0, initialData, response.getStartRow(), result.length);
requestresultSet.setEndRowsetInitialData(endRowinitialData);
dataSource.fetchData(criteria, createUpdateCallback(), request resultSet.setInitialSort(listGrid.getSort());
resultSet.setCriteria(listGrid.getCriteria());
listGrid.setData(resultSet);
}
|
Attachments