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 |
---|
|
|
private void updateAllonRefresh() {
DataSource dataSource = listGrid.getDataSource();
Criteria criteria = listGrid.getCriteria();
Integer[] visibleRows = dataSourcelistGrid.fetchData(criteria, createUpdateAllCallback()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 ResultSet resultSetrequest = new ResultSetDSRequest(dataSource);
request.setStartRow(startRow);
request.setEndRow(endRow);
resultSetrequest.setInitialLengthsetSortBy(responselistGrid.getTotalRowsgetSort());
dataSource.fetchData(criteria, new DSCallback() {
resultSet.setInitialData(response.getData());
@Override
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;
Integer endRow = (visibleRows[1] + listGrid.getResultSet().getResultSize()
// correctly position the result in the resultset's cache
Record[] result = response.getData();
Record[] DSRequestinitialData request = new DSRequestRecord[response.getTotalRows()];
System.arraycopy(result, 0, initialData, requestresponse.setStartRow(startRowgetStartRow(), result.length);
requestresultSet.setEndRowsetInitialData(endRowinitialData);
dataSource.fetchData(criteria, createUpdateCallback(), request resultSet.setInitialSort(listGrid.getSort());
resultSet.setCriteria(listGrid.getCriteria());
listGrid.setData(resultSet);
}
|
Attachments