Wrapping multiple data source saves into a single call

4 posts, 0 answers
  1. Bob
    Bob avatar
    138 posts
    Member since:
    Sep 2012

    Posted 31 Dec 2013 Link to this post

    We have a form with 3 tabs. Each tab has an editable grid in batchMode. We want to have a single save button on the page.

    It will need to call the save of each grid. However, it appears the grid sync doesn't return a promise. 

    What is the suggested way to do this, checking there were no errors in the first call before making the next. Does the sync event return error info? Is the sync event called even if there is an error? If would be great if sync returned a promise but it doesn't seem to. I'm not sure if I can wrap these in a jquery or underscore deferred in some way?

    BOb
  2. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 01 Jan 2014 Link to this post

    Hello Bob,

    It is not clear whether the three Grids are bound to the same data. If this is the case, then using a single shared Kendo UI DataSource instance is possible, which will allow you to use one sync() method call.

    If the data is different, the using a single request to sync all three dataSource instances will require custom coding and manual Ajax requests. In my opinion such a complexity is highly unnecessary.

    In case you need the DataSources to sync in a particular order, you can use their events to trigger syncing of the next instance, once the previous one has finished.

    http://docs.kendoui.com/api/framework/datasource

    Regards,
    Dimo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. dee
    dee avatar
    4 posts
    Member since:
    Jul 2016

    Posted 07 Jul in reply to Dimo Link to this post

    Dimo said:
    If the data is different, the using a single request to sync all three dataSource instances will require custom coding and manual Ajax requests. In my opinion such a complexity is highly unnecessary.
     



    Hi Dimo,
    I'm afraid I am facing a similar problem and need an advice.
    Because of the UI limitations I am forced to use multiple listview controls on the same page. Each of the listviews would only have a one object bound from the initial array of objects.
    I am not quite sure how to move on with the saving though cause would need to save them all at once.
    At first I've thought that I'd need to be able to create a master datasource where each of it's items would be a separate datasource for each of the listviews, but so far I see that is not possible.

    So currently I have an array of datasources, where datasource[i] would be bound to a listviews[i].

    var products = [{ProductID:1, ProductName:"Prod1"}, {ProductID:2, ProductName:"Prod2"}]
                      var dataSources = [];
              var listViews = [];
              var dataSources[0] = new kendo.data.DataSource({
                    data: products[0],
                    schema: {
                      model: {
                        id: "ProductID",
                        fields: {
                          ProductID: { editable: false, nullable: true },
                          ProductName: { validation: { required: true} }
                        }
                      }
                    }
                  });
     
              var listViews[0] = $("#listView").kendoListView({
                dataSource: dataSources[0],
                template: kendo.template($("#template0").html()),
                editTemplate: kendo.template($("#editTemplate0").html())
              }).data("kendoListView");
               
                var listViews[1] = $("#listView").kendoListView({
                dataSource: dataSources[0],
                template: kendo.template($("#template1").html()),
                editTemplate: kendo.template($("#editTemplate1").html())
              }).data("kendoListView");
  5. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 08 Jul Link to this post

    Hello Dee,

    Custom data retrieval and saving logic can be implemented with a custom DataSource transport. The following documentation article provides information and examples:

    http://docs.telerik.com/kendo-ui/framework/datasource/crud

    Local transport and custom transport is practically the same thing, so follow the guidelines for local transport. The idea will be that remote requests will not be managed by the Kendo UI DataSource instances directly, but by custom logic, which interacts with the transport functions, and possibly, with the DataSource methods and events.

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource

    Regards,
    Dimo
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready