I'm bundling all my updates into one request by using the method suggested in the example "GridSyncChangesWithOneRequest".
The actual call is:
$.ajax({
url:
"/Home/UpdateCreateDelete"
,
data: data,
type:
"POST"
,
error:
function
() {
//Handle the server errors using the approach from the previous example
},
success:
function
() {
alert(
"update on server is completed"
);
grid.dataSource._destroyed = [];
//refresh the grid - optional
grid.dataSource.read();
}
})
5 Answers, 1 is accepted
Oops, that wasn't supposed to happen.
OK, continuing from the above post.
I do need to refresh the grid, but ideally I would like to return the new data in the same call as the update. I tried just repopulating the data, but dates were displayed incorrectly. I realise that the dataSource read is doing quite a lot of work behind the scenes. Is there any way to hook into this? I tried several things but couldn't get it to work as well as grid.dataSource.read() (which is an extra server call).
success:
function
(e) {
grid.dataSource._destroyed = [];
//Things that didn't quite work...
//grid.dataSource._storeData(true);
//grid.dataSource._change({ action: "sync" });
//grid.dataSource.success(e.Data);
//grid.dataSource.data(grid.dataSource.reader.parse(e.Data));
//grid.dataSource.data(e.Data);
}
Is there any way of doing this or is it just something that isn't supported?
Cheers,
Mark
Hello Mark,
I'm afraid I'm not sure what is this "GridSyncChangesWithOneRequest" example you have mentioned. Could you please provide a link to it?
Regarding your question. You should be able to load the data, using the DataSource data method. However, this expects that the data matches the defined format and values are already converted to the appropriate types. Also depending on the settings (such as if serveroperation is enabled) passing the data may yield different results. Unfortunately, the given description does not provide enough information about the exact settings used. Thus, maybe you could provide a simplified runnable sample which demonstrate the case. This will allow us to provide you with more to-the-point answer.
Either way, calling the read method of the DataSource should be most generic solution to re-refresh the data.
Regards,Rosen
Telerik
Sorry, probably gave the wrong name for that example. The file is called gridsaveallchangeswithonerequest.
http://www.telerik.com/support/code-library/save-all-changes-with-one-request
I'll see if I can produce a runnable example.
Hello Mark,
Thanks for pointing me to the sample in question. In this particular scenario you could try using the following approach in order to load the data manually:
success:
function
(data) {
alert(
"update on server is completed"
);
grid.dataSource._destroyed = [];
var
dataSource = grid.dataSource;
grid.dataSource.data(dataSource.reader.data(data));
}
Where the action method returns all of the data inside a DataSourceResult instance.
return
Json(
new
DataSourceResult {
Data = allOrders
});
Rosen
Telerik
Perfect. That is exactly what I was looking for.
Many thanks.