I am using a ListGrid with a data source and I am updating records in the list based on events from the server. When I update fields that are used to sort the ListGrid, the values displayed in the ListGrid change, but the rows do not move to their new sort positions.
Is there something I have to do to make the grid re-sort when records are changed?
Here's my update code:
Is there something I have to do to make the grid re-sort when records are changed?
Here's my update code:
Code:
public static void updateListGridRecord(ListGrid grid, String primaryKeyField, Map<String, Object> properties) {
Record oldRecord = findOldListGridRecord(grid, properties.get(primaryKeyField), primaryKeyField);
if( oldRecord == null ) {
return; // no old record; no need to update
}
updateListGridRecord(grid, oldRecord, properties);
}
protected static Record findOldListGridRecord(ListGrid grid, Object recordId, String primaryKeyField) {
ResultSet resultSet = (grid.isGrouped() ? grid.getOriginalResultSet() : grid.getResultSet());
Record record = null;
if( resultSet != null ) {
record = resultSet.find(primaryKeyField, recordId.toString());
}
return record;
}
private static void updateListGridRecord(ListGrid grid, Record oldRecord, Map<String, Object> properties) {
Record record = new ListGridRecord(oldRecord.getJsObj());
for( String key: properties.keySet() ) {
record.setAttribute(key, properties.get(key));
}
updateCache(grid, record, DSOperationType.UPDATE);
}
protected static void updateCache(ListGrid grid, Record record, DSOperationType opType) {
DataSource dataSource = grid.getDataSource();
DSRequest request = new DSRequest();
request.setOperationType(opType);
request.setDataSource(dataSource.getID());
DSResponse carrier = new DSResponse();
carrier.setData(new Record[]{record});
dataSource.updateCaches(carrier, request);
}
Comment