If your ListGrid is bound to a dataSource, it should automatically display changes to any records its currently displaying. In other words you shouldn’t need to take additional action in the callback function to display the new value.
This happens because a databound ListGrid has its data property set to a ‘resultSet’ automatically, when the grid performs a fetch from the server - and subsequent changes to the datasource data should notify the resultSet of the changes, which ensures they are displayed in the grid.
However you are correct that you have to re-select the record after the value updates.
The easiest way to select the record in question would be to call “selectRecord()” on the listGrid, passing in the row number of the record in question.
This will be done from the callback method passed into the updateData method on the DataSource. A quick note here: In SmartClient release 5.5.1, the callback was documented as having parameters of
data, dsResponse, dsRequest
This is not correct - instead the parameters are
dsResponse, data, dsRequest
You will be using the data parameter to determine which record to select so it is important to get the params in the correct order. We have updated our documentation to correct this error, so subsequent releases are documented accurately.
Here’s some sample code you can apply to the “showcase application” example on the website.
- First navigate to the app: here.
- Then select the “JS” tab from the tabSet, and add the following code to the bottom of the application:
isc.IButton.create({
ID:"updateButton",
title:"Update",
left:200,
width:80,
autoDraw:true,
click: function () {
var ds = isc.DataSource.getDataSource("supplyItem"),
record = itemList.data.get(0);
// Call the "updateData" method on the datasource,
// making a change to the 'unitCost' of the first record in the grid
// Pass in a callback function to select the record when the update
// completes
ds.updateData({itemID:record.itemID, unitCost:222},
function (dsResponse, data, dsRequest) {
var rowNum = itemList.data.indexOf(data[0]);
if(rowNum >= 0) itemList.selectRecord(rowNum);
}
)
}
});
updateButton.bringToFront();
Now hit the “try it” button, (and then the “Show Example” button to actually run the example).
You will see the ‘update’ button floating near the top left of the app.
- Select a row from the treeGrid on the left to populate the ListGrid with records
- Now hit the “update” button
You should see the record’s unit cost be updated to “222”, and be selected.
It should be very easy to adapt this code to fit your use case.
Please let us know if you run into any problems.
Regards
Isomorphic Software