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

Resource datasource from JSON

2 Answers 222 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 09 Mar 2015, 02:59 PM
I've got a api endpoint that spits out the following JSON:

[{"Start": "2015-03-08T21:43:31Z", "Attendee": ["andrew", "bobo"], "End": "2015-03-08T22:43:33Z", "Description": "", "TaskID": 1, "Title": "Test Event", "OwnerID": 2, "IsAllDay": false}]

            schema: {
                model: {
                    id: "taskId",
                    fields: {
                        taskId: { from: "TaskID", type: "number" },
                        title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                        start: { type: "date", from: "Start" },
                        end: { type: "date", from: "End" },
                        ownerId: { from: "OwnerID", defaultValue: 1 },
                        attendee: { from: "Attendee"},
                        isAllDay: { type: "boolean", from: "IsAllDay" }
                    }
                }
        },

        resources: [
            {
                field: "attendee",
                title: "Attendee",
                dataSource: [
                    { text: "Alex", value: 1, color: "#f8a398" },
                    { text: "Bob", value: 2, color: "#51a0ed" },
                    { text: "Charlie", value: 3, color: "#56ca85" }
                ]
            }
        ]
     },


All the examples I've seen for custom resources are not derived but are hard coded.  How do I get the values JSON into the dataSource resource for attendee?













2 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 09 Mar 2015, 05:18 PM
Is this how you have to do it?  Create a separate data source resource just to get the list of attendees?  This works, but it seems verbose.

        resources: [
            {
                field: "Attendee",
                title: "Attendee",
                dataSource: {
            transport: {
               read: {
                   url: "/scheduler/getattendees/",
                   dataType: "json"
               },
                },
                schema: {
            model:{
            id: "ID",
            fields: {
            text: {from: "Attendee"}
            }
            }
            }
            },
            }
        ]
0
Vladimir Iliev
Telerik team
answered on 11 Mar 2015, 07:52 AM
Hi Andrew,

You are correct - if you need to load the resource items from remote source you should set it's "dataSource" option. In this case it's not required to define the "schema" option (you can leave only the transport) of the dataSource as the data would be read-only on the client side. 

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Scheduler
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Share this question
or