Error thrown when editing data from read-only remote source

6 posts, 0 answers
  1. Jesper
    Jesper avatar
    25 posts
    Member since:
    Jun 2012

    Posted 27 Jun 2012 Link to this post

    I'm fetching data form a remote source using the DataSource transport. 

    The remote is read-only, so I only specify the read-object in the transport, like so:

    transport: {
        read: {
            data: {
                f:'getOrderSuggestion'
            }
        }
    }

    The data is to be edited locally in a Kendo Grid and then posted manually to another server.

    The problem is, as soon as the user finishes editing a row, the Grid tries to persist the changes. The sync()-method of the DataSource is called and crashes when the RemoteTransport object crashes as it tries to fetch for the update method, which does not exists.

    The error:

    1. Uncaught TypeError: Cannot read property 'data' of undefined kendo.web.js:5038
      1. Class.extend.setupkendo.web.js:5038
      2. Class.extend.updatekendo.web.js:5025
      3. Observable.extend._promisekendo.web.js:5339
      4. f.extend.Deferredjquery.min.js:2
      5. Observable.extend._promisekendo.web.js:5338
      6. Observable.extend._sendkendo.web.js:5365
      7. Observable.extend.synckendo.web.js:5265
      8. Widget.extend.saveRowkendo.web.js:17569
      9. Widget.extend.editRowkendo.web.js:17411
      10. f.event.dispatchjquery.min.js:3
      11. f.event.add.h.handle.ijquery.min.js:3


    The code (from the GPL-version of Kendo UI):

    var Remote Transport = Class.extend({
            // ....
            // Other stuff
            // ....
     
            setup: function(options, type) {
                options = options || {};
     
                var that = this,
                    parameters,
                    operation = that.options[type], // <<<----- undefined if transport.update isn't defined and update is called
                    data = isFunction(operation.data) ? operation.data() : operation.data;
     
                options = extend(true, {}, operation, options);
                parameters = extend(data, options.data);
     
                options.data = that.parameterMap(parameters, type);
     
                if (isFunction(options.url)) {
                    options.url = options.url(parameters);
                }
     
                return options;
            }
    });

    Is there any way of making the DataSource fetch remote data, but edit only locally? 
  2. Devon
    Devon avatar
    28 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    I'm having the exact opposite problem.

    I'm trying to sync changes to my remote datasource but it's only changing them locally. 

    Here's my code:

    Datasource:

    var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "http://localhost:8080/databases/shipping/docs",
                        dataType: "json",
                        data: {
                            q: "javascript"
                        }
                    },
                    update: {
                        url: "http://localhost:8080/databases/shipping/docs",
                        dataType: "json"
                    }
                },
                schema: {
                    model: {
                        id: "id",
                        fields: {
                            Name: { type: "string" },
                            Telephone: { type: "string" },
                            Address: { type: "string" },
                            Suburb: { type: "string" },
                            City: { type: "string" },
                            Province: { type: "string" },
                            Country: { type: "string" },
                            PostalCode: { type: "string" },
                            DeliveryStatus: { type: "string" },
                            Packages: { type: "auto" }
                        }
                    }
                }
            });

    "Save Changes" Button Click: It might be a bit messy because I've been trying loads of different techniques

    var packageId;
     
            function saveChanges(e) {
                var button = e.button,
                    item = packageDataSource.get(button.data("itemId"));
                packageId = item.ID;
                 
                dataSource.fetch(function () {
                    var packageToUpdate = dataSource.data()[id].Packages[packageId];
                    packageToUpdate.Status = "Delivered";
                    dataSource.sync();
                    console.log(dataSource);
                });
            }

    I can see the changes reflecting in my console when I check the console.log(dataSource); after the dataSource.sync(); but when I check my remote database there's no change.
  3. Jesper
    Jesper avatar
    25 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2012 Link to this post

    To be honest, I don't really think that our problems are related. Maybe you should start a separate thread for your issue?

    I took a quick look though.

    To my knowledge, Kendo UI DataSources use what Telerik calls Observable objects/arrays to keep track of dirty data items. 
    Observable objects trigger "changed"-events whenever they are modified, but this only works when you use the intendet set()-functions.
    I suspect that since you don't use the .set()-function to set the data in your object, the data changes, but the DataSource hasn't detected it. Thus - when you call sync() the datasource thinks that no data item is dirty, and hence no data is sent.

    Make sense?
  4. Devon
    Devon avatar
    28 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    I'll start a separate thread now.

    Thanks for having a look.

    I get what you're saying but, being new to Kendo and mobile development in general, I'm not sure where I would use the set() function?

    Any idea??
  5. Jesper
    Jesper avatar
    25 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2012 Link to this post

    You could try this:

    packageToUpdate.set("Status", "Delivered");
  6. Devon
    Devon avatar
    28 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    I gave it a try but still nothing.

    This is the new thread btw...

    http://www.kendoui.com/forums/framework/data-source/error-trying-to-sync-to-remote-datasource.aspx 
Back to Top