I have a listgrid with a recordclick function. When the user double clicks on a row, a server call is made and this row's data is updated. I want to show the change that has been made. Currently I am updating by just calling fetch again, but I do not want to have to request for the whole record list again. How can I just request for that one row without replacing the whole list? When I call fetchData with criteria to match that row updated, my whole list gets replaced.
Announcement
Collapse
No announcement yet.
X
-
Hi Acura,
How are you updating the record on the server? If you're calling DataSource.updateData(...) the ListGrid record should automatically update to reflect the change.
If this doesn't apply in this case, can you describe the scenario so we can understand what you're doing?
Thanks
Isomorphic Software
Comment
-
Sure - the double click function is a separate call to our server - it is external from SmartClient objects. When this double click is processed in the server side, the server side data object corresponding to the clicked row is updated. Once this is complete, we send a request to the listgrid to update its whole list via listGrid.fetchData() which updates the whole list.
The double click behaviour must stay the same but instead of fetching all the data, I just want to update that clicked row.
Comment
-
If the double click triggers a request to the server, you may want to consider just handling this as a SmartClient 'update' request on the field and having custom server logic to make whatever changes you need on the back-end.
However, if this isn't practical in your usage, you could handle this with DataSource.updateCaches().
This is a way to notify a dataSource that its data has changed on the server so all databound components reflect the change, as if the change had been made using a standard CRUD operation on the dataSource. In this case:
1) If you don't already have the updated record information on the client, fetch it from the ds using a simple dataSource.fetchData(...) and use the 'callback' parameter from that call to proceed to step 2.
Note that the criteria passed to fetch data should be a simple object where the primary key field is set to the primary-key field value on the record you want to refresh. This will fetch just that record from the server.
2) Once you have the updated record on the client, put together a new DSResponse to let the dataSource no the record has been updated.
This will be a javascript object with "dataSource" set to the ID of the dataSource, operationType set to "update", and data set to the update record.
Pass this object to 'updateCaches()' on the grid's dataSource object, and it (as well as any other grids bound to the DS, showing this record) will refresh to display the changed value.
Comment
-
DataSource.fetchRecord() issues a fetch request against the dataSource and gives you back the requested record.
Its exactly the same as calling DataSource.fetchData() except it derives criteria from an existing record, rather than you building the criteria yourself.
So - fetchRecord() would be an option instead of 'fetchData()' for retrieving the modified record in the first step above, but you'd still need to tell the list grid to refresh this single cached row to display the changes somehow.
Using "updateCaches()" on the dataSource is the correct way to handle this -- it'll refresh all ListGrids bound to the datasource and keep the data consistent across your application.
Comment
-
Just to update - I got this working with the code below. I was initially having problems because listGrid.dataSource was just the ID of the data source and not the actual ds object:
Code:$wnd.isc.DataSource.get(listGrid.dataSource).fetchRecord(fetchIds, function (dsResponse, updateData, dsRequest) { this.updateCaches({ operationType:"update", data: updateData }) },null);
Comment
-
DataSource.fetchRecord() will only handle being passed a single record.
However fetchData() will allow you to do this. You will have to turn your list of records into a criteria object but this should be straightforward to achieve - basically you'd define an AdvancedCriteria object with operator set to "IN_SET", fieldName set to the primary key field within your DS, and value set to an array of primary key values for the records you care about.
Comment
Comment