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

Error thrown when editing data from read-only remote source

5 Answers 223 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 27 Jun 2012, 06:04 AM
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? 

5 Answers, 1 is accepted

Sort by
0
Devon
Top achievements
Rank 1
answered on 13 Aug 2012, 01:48 PM
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.
0
Jesper
Top achievements
Rank 1
answered on 13 Aug 2012, 02:13 PM
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?
0
Devon
Top achievements
Rank 1
answered on 13 Aug 2012, 02:20 PM
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??
0
Jesper
Top achievements
Rank 1
answered on 13 Aug 2012, 02:26 PM
You could try this:

packageToUpdate.set("Status", "Delivered");
0
Devon
Top achievements
Rank 1
answered on 13 Aug 2012, 02:33 PM
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 
Tags
Data Source
Asked by
Jesper
Top achievements
Rank 1
Answers by
Devon
Top achievements
Rank 1
Jesper
Top achievements
Rank 1
Share this question
or