For those following this thread, the following documented code enables client-side logic to update any field of any row without invoking the server. (This could be useful for rapidly updating fields via HTTP streaming)
Note that, any normal client-server round-trip that updates rows you update via this client-side technique will of course overwrite the values you push here without warning!
Code:
public ListGridRecord FindListGridRecord(ListGrid oGrid, String sFieldName, String sFieldValue) {
// Returns the ListGridRecord from oGrid having 'sFieldName' set to 'sFieldValue'
//***WEAK: Assuming the criteria will only return one record!
//***TODO!!: SmartGWT 2.5 will likely have a better native function to replace this call
Record oRecord = oGrid.getResultSet().find(sFieldName, sFieldValue); //***LEARN: How to find a ListGridRecord by primary id as per technique at http://forums.smartclient.com/showthread.php?t=16988&page=2
ListGridRecord oRec = new ListGridRecord(oRecord.getJsObj());
return oRec;
}
public void UpdateGridField_ClientSide(ListGrid oGrid, String sKeyName, String sKeyValue, String sFieldName, String sFieldValue) {
// Advanced client-side function that updates field 'sFieldName' to 'sFieldValue' for grid record with primary key 'sKeyName' to 'sKeyValue' directly without the normal client/server round trip
// (Function is useful for rapidly changing a ListGrid record normally attached to a server datasource wihout the server round-trip.)
// (Used upon receiving Comet message that a frequently changed field has changed)
//***WARN: Note that future server updates to this row will overwrite the value we push in here!
ListGridRecord oRec = FindListGridRecord(oGrid, sKeyName, sKeyValue); // Obtain the existing data already in the grid's cache for this row
if (oRec == null) //***TODO: logging!
return;
DSRequest oDSReq = new DSRequest(); // Create a nearly-blank DSRequest object that will tell updataCaches() below we just need to update what we pass into via oDSResp
oDSReq.setOperationType(DSOperationType.UPDATE);
DSResponse oDSResp = new DSResponse(); // Form a DSResponse with only one record to update
Record[] aRec = new Record[1];
oRec.setAttribute(sFieldName, sFieldValue); // Change the value of the requested field
aRec[0] = oRec;
oDSResp.setData(aRec);
oGrid.getDataSource().updateCaches(oDSResp, oDSReq); // Ask the datasource to update its cache. This will automatically update the UI of all GUI components linked to this datasource
}
Jean-Pierre
Leave a comment: