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

Specifying the fields to send on an 'update' command

2 Answers 176 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 07 May 2013, 03:10 PM
Hi,
I am using the Data Source object to connect to a SharePoint 2013 ODATA source using REST and then use this as the data for a Kendo UI Grid.
The Data Source reads the list correctly and populates the grid, but when I update an item in the Kendo UI Grid the following error is returned by the REST end point.

The property '__deferred' does not exist on type 'SP.SecurableObject'. Make sure to only use property names that are defined by the type.

This is caused by the Data Source returning all the properties from the initial read request and then returning in the update command. SharePoint returns __deferred properties with a REST url to defer loading, but is throwing a wobbly if they are returned back in an update command.
Below is my Data Source
01.var dataSource = new kendo.data.DataSource({
02.        type: "odata",
03.        transport: {
04.            read: {
05.                url: listUrl,
06.                type: "GET",
07.                dataType: "json",
08.                contentType: "application/json;odata=verbose",
09.                headers: {
10.                    "accept": "application/json;odata=verbose"
11.                }
12.            },
13.            create: {
14.                url: listUrl,
15.                type: "POST",
16.                dataType: "json",
17.                contentType: "application/json;odata=verbose",
18.                headers: {
19.                    "accept": "application/json;odata=verbose",
20.                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
21.                }
22.            },
23.            update: {
24.                url: function (data) {
25.                    return listUrl + "(" + data.ID + ")";
26.                },
27.                beforeSend: function (jqXhr, options) {
28. 
29.                    var data = JSON.parse(options.data);
30. 
31.                    jqXhr.setRequestHeader("If-Match", data.__metadata.etag);
32. 
33.                },
34.                type: "POST",
35.                dataType: "json",
36.                contentType: "application/json;odata=verbose",
37.                headers: {
38.                    "accept": "application/json;odata=verbose",
39.                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
40.                    "X-HTTP-Method": "MERGE"
41.                },
42.            },
43.            destroy: {
44.                url: function (data) {
45.                    return listUrl + "(" + data.ID + ")";
46.                },
47.                type: "DELETE",
48.                dataType: "json",
49.                contentType: "application/json;odata=verbose",
50.                headers: {
51.                    "accept": "application/json;odata=verbose",
52.                    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
53.                    "X-HTTP-Method": "MERGE",
54.                    "If-Match": "*"
55.                }
56.            }
57.        },
58.        pageSize: 20,
59.        schema: {
60.            data: "d.results",
61.            model: {
62.                id: "ID",
63.                fields: {
64.                    ID: { editable: false, nullable: false },
65.                    Title: { validation: { required: true } },
66.                    Body1: { validation: { required: true } },
67.                    Votes: { type: "number", validation: { required: true, min: 1 } },
68.                }
69.            }
70.        }
71.    });
Any idea what I can do to only return the fields that are updateable.
Cheers

2 Answers, 1 is accepted

Sort by
0
Toby
Top achievements
Rank 1
answered on 08 May 2013, 05:53 PM
Here is a work around using the parameterMap configuration.
I have a data model defined using the kendo.data.Model.define and I'm checking against that to see which properties to send back in the update.
Is this correct or should the data source object be doing this?
parameterMap: function (data, type) {
                 
                if (type == "update") {
                    for (var property in data) {
                        if (property != "__metadata" && !question.fields[property])
                            delete data[property];
                    }
                }
 
                return kendo.stringify(data);
            }
0
Alexander Valchev
Telerik team
answered on 09 May 2013, 10:57 AM
Hello Toby,

Your approach is correct. If request parameters have to be changed, the developer should do that in the parameterMap function of the transport.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Toby
Top achievements
Rank 1
Answers by
Toby
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or