Minimising Server Calls when Updating

6 posts, 1 answers
  1. Mark
    Mark avatar
    11 posts
    Member since:
    Nov 2015

    Posted 25 Jan Link to this post

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

  2. Mark
    Mark avatar
    11 posts
    Member since:
    Nov 2015

    Posted 25 Jan Link to this post

    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

     

     

     

     

     

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 28 Jan Link to this post

    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
  5. Mark
    Mark avatar
    11 posts
    Member since:
    Nov 2015

    Posted 28 Jan in reply to Rosen Link to this post

    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. 

      

     

  6. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 29 Jan Link to this post

    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
  7. Mark
    Mark avatar
    11 posts
    Member since:
    Nov 2015

    Posted 29 Jan in reply to Rosen Link to this post

    Perfect. That is exactly what I was looking for.

    Many thanks.

Back to Top
UI for ASP.NET MVC is VS 2017 Ready