Search code examples
jsonrestsharepointkendo-scheduler

SharePoint data does not display in Kendo Scheduler


Data is retrieved using the REST call in my transport, but the event does not display in Kendo Scheduler. I am interested in only displaying data at this point, the update is not working

    $("#scheduler").kendoScheduler({
    date: new Date("2018/11/11"),
    startTime: new Date("2018/11/11 07:00 AM"),
    height: 600,
    views: [
        "day",
        "workWeek",
        "week",
        { type: "month", selected: true },
        "agenda",
        { type: "timeline", eventHeight: 50}
    ],
    add: function (e) {
    },
    change: function (e) {
    },
    error: function (e) {

        //TODO: handle the errors

        alert(e.errorThrown);

    },
    dataSource: {
        transport: {
            read: {
                url: "https://SharePoint URL/apps/crp/_api/web/lists/getbytitle('list name')/items?$expand=Author&$select=Author/Id,Author/Title,Title,Start1,OData__x0045_nd1,RecurrenceRule,RecurrenceParentID,CategoryDescription,IsAllDay&$filter=Start1 ge datetime'2018-11-01T00:00:00Z'",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json; odata=verbose");
                }
            },
            add: function (e) {
            },
            error: function (e) {
                //TODO: handle the errors
                alert(e.errorThrown);
            },
            update:
                {
                    url: function (data) {
                        alert('updating');
                        return "https://SharePoint URL/_api/web/lists/getbytitle(listname)/items" + "(" + data.ID + ")";
                    },
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;odata=verbose",
                    headers: {
                        "accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "If-Match": "*",
                        "X-HTTP-Method": "MERGE",
                    },
                },
            parameterMap: function (data, type) {
                if (data.models) {
                    alert(kendo.stringify(data.models));
                    return {
                        models: kendo.stringify(data.models)
                    }
                }
            }
        },
        schema: {
            model: {
                id: "ID",
                fields: {
                    ID: { from: "ID", type: "number" },
                    title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                    start: { type: "date", from: "Start1" },
                    end: { type: "date", from: "OData__x0045_nd1" },
                    recurrenceRule: { from: "RecurrenceRule" },
                    recurrenceId: { from: "RecurrenceParentID", type: "number" },
                    description: { from: "CategoryDescription" },
                    isAllDay: { type: "boolean", from: "IsAllDay" } //,
                }
            }
        }
    }
});

Reviewing the JSON call, data is retrieved properly but does not display in the Scheduler. I tried capturing events in the datasource, that does not look like it is processed, so the datasource does not seem to populate (change or add events).

Data returned looks like this after JSON call:

"{\"d\":{\"results\":[{\"__metadata\":{\"id\":\"Web/Lists(guid'2abecf66-35ed-4c67-b1f1-8b7255ebf0e2')/Items(1)\",\"uri\":\"https://SharePoint url/_api/Web/Lists(guid'2abecf66-35ed-4c67-b1f1-8b7255ebf0e2')/Items(1)\",\"etag\":\"\\"4\\"\",\"type\":\"SP.Data.6001C5110ListItem\"},\"Author\":{\"__metadata\":{\"id\":\"43c25e84-bf91-4d7d-951f-c480d9b2173f\",\"type\":\"SP.Data.UserInfoItem\"},\"Id\":5,\"Title\":\"SP USer\"},\"Title\":\"6001-C5-110\",\"Start1\":\"2018-11-14T15:00:00Z\",\"OData__x0045_nd1\":\"2018-11-14T17:00:00Z\",\"RecurrenceRule\":null,\"RecurrenceParentID\":null,\"CategoryDescription\":\"My Description\",\"IsAllDay\":null}]}}"


Solution

  • Added data: to the schema section of the datasource, thank you Sandun for pointing me in right direction, I defined the model for the scheduler without specifying the data.

            schema: {
                data: function (data) {
                    return data.d && data.d.results ? data.d.results : [data.d];
                },
                model: {
                    id: "ID",
                    fields: {
                        ID: { from: "ID", type: "number" },
                        title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                        start: { type: "date", from: "Start1" },
                        end: { type: "date", from: "OData__x0045_nd1" },
                        recurrenceRule: { from: "RecurrenceRule" },
                        recurrenceId: { from: "RecurrenceParentID", type: "number" },
                        description: { from: "CategoryDescription" },
                        isAllDay: { type: "boolean", from: "IsAllDay" } //,
                        // startTimeZone: "Etc/UTC",
                        // endTimeZone: "Etc/UTC"
                        // description: { from: "Description" } 
                    }
                }
            }