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

Events not being called

3 Answers 91 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 07 Jan 2016, 06:04 PM

I have a project that should be very simple that uses one of the demos as a template, yet it is not loading data from the server - I am sure I am missing something simple, if anyone can help identify?

Things of note:

* If I give it a datasource manually, items appear, so I guess the events for "transport -> read" are not being triggered?

*If I put in a navigate option (navigate: scheduler_navigate), this gets called, and I see JSON data returned from the server - however, my understanding is this should not be necessary as "transport -> read" takes care of polling data from the server/data-source?

thanks.

Allen.

 

(1) The JS

 

// scheduler setup
            scheduler = $("#scheduler").kendoScheduler({
                views: ["day", { type: "workWeek" }, "week", "month", "agenda", { type: "timeline", eventHeight: 30, selected: true }],
                timezone: "Etc/UTC",
                majorTick: 30,
                datasource: {
                    batch: true,
                    transport: {
                        read: {
                            url: "/Home/LoadTasks",
                            datatype: "jsonp"
                        },
                        update: {
                            url: "/home/update",
                            datatype: "jsonp"
                        },
                        create: {
                            url: "/home/create",
                            datatype: "jsonp"
                        },
                        destroy: {
                            url: "/home/destroy",
                            datatype: "jsonp"
                        },
                        parametermap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return { models: kendo.stringify(options.models) };
                            }
                            if (operation == "read") {
                                var scheduler = $("#scheduler").data("kendoscheduler");
                                return {
                                    type: "workweek",
                                    start: kendo.tostring(new date(scheduler.view().startdate()), "u"),
                                    end: kendo.tostring(new date(scheduler.view().enddate()), "u")
                                }
                            }
                        }
                    }
                },
                    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" },
                                startTimezone: { from: "StartTimezone" },
                                endTimezone: { from: "EndTimezone" },
                                description: { from: "Description" },
                                recurrenceId: { from: "RecurrenceID" },
                                recurrenceRule: { from: "RecurrenceRule" },
                                recurrenceException: { from: "RecurrenceException" },
                                isAllDay: { type: "boolean", from: "IsAllDay" }
                            }
                        }
                //    }
                },
                resources: resourceArray,
                group: {
                    resources: ["branches", "users"],
                    orientation: "vertical"
                },
                startTime: new Date("2013/6/13 07:00 AM"),
                height: 600
                }
            )

 

(2) Controller

         public JsonResult LoadTasks(string type, string start, string end)

        {
            TaskRepository TaskRep = new TaskRepository();
            return this.Jsonp(TaskRep.dateRange(type, start, end));
        }

 

(3) VM / Repo

 public IList<SchedulerEvent> dateRange(string type, string startDate, string endDate)
        {
            List<SchedulerEvent> result = new List<SchedulerEvent>();
            DateTime dateStart = Convert.ToDateTime(startDate);
            DateTime dateEnd;
            if (endDate != "")
            {
                dateEnd = Convert.ToDateTime(endDate);
            }
            if (result == null || UpdateDatabase)
            {


                    if (type == "workWeek")
                    {
                        dateEnd = dateStart.AddDays(4);

                        SchedulerEvent itm1 = new SchedulerEvent();
                        itm1.TaskID = 1;
                        itm1.Title = "Task 1";
                        itm1.Start = DateTime.SpecifyKind(dateStart, DateTimeKind.Utc);
                        itm1.End = DateTime.SpecifyKind(dateEnd, DateTimeKind.Utc);
                        itm1.StartTimezone = null;
                        itm1.EndTimezone = null;
                        itm1.Description = "Description";
                        itm1.IsAllDay = false;
                        itm1.RecurrenceRule = null;
                        itm1.RecurrenceException = null;
                        itm1.branchID = 10;
                        itm1.userID = 1;
                        result.Add(itm1);


                        SchedulerEvent itm2 = new SchedulerEvent();
                        itm2.TaskID = 1;
                        itm2.Title = "Task 2";
                        itm2.Start = DateTime.SpecifyKind(dateStart.AddDays(1).AddMinutes(30), DateTimeKind.Utc);
                        itm2.End = DateTime.SpecifyKind(dateEnd.AddDays(1).AddMinutes(30), DateTimeKind.Utc);
                        itm2.StartTimezone = null;
                        itm2.EndTimezone = null;
                        itm2.Description = "Description";
                        itm2.IsAllDay = false;
                        itm2.RecurrenceRule = null;
                        itm2.RecurrenceException = null;
                        itm2.branchID = 20;
                        itm2.userID = 2;
                        result.Add(itm2);


                        SchedulerEvent itm3 = new SchedulerEvent();
                        itm3.TaskID = 1;
                        itm3.Title = "Task 3";
                        itm3.Start = DateTime.SpecifyKind(dateStart.AddDays(2).AddMinutes(45), DateTimeKind.Utc);
                        itm3.End = DateTime.SpecifyKind(dateEnd.AddDays(2).AddMinutes(45), DateTimeKind.Utc);
                        itm3.StartTimezone = null;
                        itm3.EndTimezone = null;
                        itm3.Description = "Description";
                        itm3.IsAllDay = false;
                        itm3.RecurrenceRule = null;
                        itm3.RecurrenceException = null;
                        itm3.branchID = 10;
                        itm3.userID = 3;
                        result.Add(itm3);




                }
                    else if (type == "timeline" || type == "day")
                    {
                        dateEnd = dateStart.AddDays(1);


                        SchedulerEvent itm1 = new SchedulerEvent();
                        itm1.TaskID = 1;
                        itm1.Title = "Task 1";
                        itm1.Start = DateTime.SpecifyKind(dateStart, DateTimeKind.Utc);
                        itm1.End = DateTime.SpecifyKind(dateEnd, DateTimeKind.Utc);
                        itm1.StartTimezone = null;
                        itm1.EndTimezone = null;
                        itm1.Description = "Description";
                        itm1.IsAllDay = false;
                        itm1.RecurrenceRule = null;
                        itm1.RecurrenceException = null;
                        itm1.branchID = 10;
                        itm1.userID = 1;
                        result.Add(itm1);


                        SchedulerEvent itm2 = new SchedulerEvent();
                        itm2.TaskID = 1;
                        itm2.Title = "Task 2";
                        itm2.Start = DateTime.SpecifyKind(dateStart.AddMinutes(30), DateTimeKind.Utc);
                        itm2.End = DateTime.SpecifyKind(dateEnd.AddMinutes(30), DateTimeKind.Utc);
                        itm2.StartTimezone = null;
                        itm2.EndTimezone = null;
                        itm2.Description = "Description";
                        itm2.IsAllDay = false;
                        itm2.RecurrenceRule = null;
                        itm2.RecurrenceException = null;
                        itm2.branchID = 20;
                        itm2.userID = 2;
                        result.Add(itm2);


                        SchedulerEvent itm3 = new SchedulerEvent();
                        itm3.TaskID = 1;
                        itm3.Title = "Task 3";
                        itm3.Start = DateTime.SpecifyKind(dateStart.AddMinutes(45), DateTimeKind.Utc);
                        itm3.End = DateTime.SpecifyKind(dateEnd.AddMinutes(45), DateTimeKind.Utc);
                        itm3.StartTimezone = null;
                        itm3.EndTimezone = null;
                        itm3.Description = "Description";
                        itm3.IsAllDay = false;
                        itm3.RecurrenceRule = null;
                        itm3.RecurrenceException = null;
                        itm3.branchID = 10;
                        itm3.userID = 3;
                        result.Add(itm3);
                  }





                }


                HttpContext.Current.Session["Tasks"] = result;



            return result;
        }

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Jan 2016, 12:34 PM

Hello Allen,

 

Looking at the code you have pasted I have noticed that the dataSource option is with incorrect casing. Note it should be camelCase not lowercase as it the snippet. This is also the same for parameterMap setting.

 

Please modify your code accordingly and see if there is change in the observed behavior.

 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Allen
Top achievements
Rank 1
answered on 11 Jan 2016, 04:56 PM

Thanks Rosen,

that got things moving, but not totally as expected.

The JS now correctly sends a network request for data, however, the data that is sent back is now showing in the scheduler control?

here is updated code:

 (1) JS

 // scheduler setup
            scheduler = $("#scheduler").kendoScheduler({
                views: ["day", { type: "workWeek" }, "week", "month", "agenda", { type: "timeline", eventHeight: 30, selected: true }],
                timezone: "Etc/UTC",
                majorTick: 30,
                dataSource: {
                    batch: true,
                    transport: {
                        read: {
                            url: "/Home/LoadTasks",
                            datatype: "jsonp"
                        },
                        update: {
                            url: "/home/update",
                            datatype: "jsonp"
                        },
                        create: {
                            url: "/home/create",
                            datatype: "jsonp"
                        },
                        destroy: {
                            url: "/home/destroy",
                            datatype: "jsonp"
                        },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return { models: kendo.stringify(options.models) };
                            }


                            if (operation == "read") {
                                var sch = $("#scheduler").data("kendoScheduler");
                                return {
                                    // add in any variables to send to server
                                    type: sch.view().name,
                                    start: kendo.toString(new Date(sch.view().startDate()), "u"),
                                    end: kendo.toString(new Date(sch.view().endDate()), "u"),
                                    //thingX : "XXX"
                                }
                                return kendo.stringify(result);
                            }
                        }
                    }
                },


                    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" },
                                startTimezone: { from: "StartTimezone" },
                                endTimezone: { from: "EndTimezone" },
                                description: { from: "Description" },
                                recurrenceId: { from: "RecurrenceID" },
                                recurrenceRule: { from: "RecurrenceRule" },
                                recurrenceException: { from: "RecurrenceException" },
                                isAllDay: { type: "boolean", from: "IsAllDay" },
                                userID: { from: "userID" },
                                branchID: { from: "branchID" },
                                resourceID: { from: "resourceID" },
                            }
                        }
                },
                resources: resourceArray,
                group: {
                    resources: ["branches", "users"],
                    orientation: "vertical"
                },
                startTime: new Date(),
                height: 600


                }
            )

(2) CS adds sample task events as follows:

 dateEnd = dateStart.AddMinutes(30);


                    SchedulerEvent itm1 = new SchedulerEvent();
                        itm1.TaskID = 1;
                        itm1.Title = "Task 1";
                        itm1.Start = DateTime.SpecifyKind(dateStart, DateTimeKind.Utc);
                        itm1.End = DateTime.SpecifyKind(dateEnd, DateTimeKind.Utc);
                        itm1.StartTimezone = null;
                        itm1.EndTimezone = null;
                        itm1.Description = "Dte range: " + dateStart.ToString() + " - " + dateEnd.ToString();
                    itm1.IsAllDay = false;
                        itm1.RecurrenceRule = null;
                        itm1.RecurrenceException = null;
                        itm1.branchID = 10;
                        itm1.userID = 1;
                        result.Add(itm1);

(3) Response received from server:

 Parsed:

ClientID: null
ClientName: null
Description: "Dte range: 11/01/2016 10:00:00 - 11/01/2016 10:30:00"
End: "/Date(1452508200000)/"
EndTimezone: null
IsAllDay: false
RecurrenceException: null
RecurrenceID: null
RecurrenceRule: null
Start: "/Date(1452506400000)/"
StartTimezone: null
TaskID: 1
Title: "Task 1"
branchID: 10
resourceID: 0
userID: 1

 

Raw:

callback([{"TaskID":1,"Title":"Task 1","branchID":10,"resourceID":0,"userID":1,"Start":"\/Date(1452506400000)\/","End":"\/Date(1452508200000)\/","Description":"Dte range: 11/01/2016 10:00:00 - 11/01/2016 10:30:00","IsAllDay":false,"RecurrenceID":null,"RecurrenceRule":null,"RecurrenceException":null,"StartTimezone":null,"EndTimezone":null,"ClientID":null,"ClientName":null},{"TaskID":1,"Title":"Task 2","branchID":20,"resourceID":0,"userID":2,"Start":"\/Date(1452594600000)\/","End":"\/Date(1452596400000)\/","Description":"Dte range: 11/01/2016 10:00:00 - 11/01/2016 10:30:00","IsAllDay":false,"RecurrenceID":null,"RecurrenceRule":null,"RecurrenceException":null,"StartTimezone":null,"EndTimezone":null,"ClientID":null,"ClientName":null},{"TaskID":1,"Title":"Task 3","branchID":10,"resourceID":0,"userID":3,"Start":"\/Date(1452681900000)\/","End":"\/Date(1452683700000)\/","Description":"Dte range: 11/01/2016 10:00:00 - 11/01/2016 10:30:00","IsAllDay":false,"RecurrenceID":null,"RecurrenceRule":null,"RecurrenceException":null,"StartTimezone":null,"EndTimezone":null,"ClientID":null,"ClientName":null}])

 

0
Rosen
Telerik team
answered on 12 Jan 2016, 08:00 AM

Hello Allen,

 

The issue is most probably caused by the fact that the schema declaration is incorrectly placed outside of the DataSource declaration. The schema is DataSource setting and should be within the DataSource configuration. Please move it to the appropriate position and see if this helps.

 

Regards,
Rosen
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
Allen
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Allen
Top achievements
Rank 1
Share this question
or