This is a migrated thread and some comments may be shown as answers.

Minimising Server Calls when Updating

5 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 25 Jan 2016, 07:07 PM

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

Sort by
0
Mark
Top achievements
Rank 1
answered on 25 Jan 2016, 07:15 PM

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

 

 

 

 

 

0
Rosen
Telerik team
answered on 28 Jan 2016, 09:11 AM

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 28 Jan 2016, 09:50 AM

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. 

  

 

0
Accepted
Rosen
Telerik team
answered on 29 Jan 2016, 01:33 PM

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
});

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 29 Jan 2016, 05:59 PM

Perfect. That is exactly what I was looking for.

Many thanks.

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or