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

How to bind datasource to the scheduler in Kendo UI using javascript?

2 Answers 164 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
xixi
Top achievements
Rank 1
xixi asked on 28 Apr 2014, 03:53 PM
I write my codes in html is OK,but when I bind the datasource using javascript,it is not ok.What's wrong with my codes?

**My View:using Meetings_Read is OK,but using javascript is not OK**

     @(Html.Kendo().Scheduler<SchedulerCustomViewDemo.Models.SchedulerTest>()
    .Name("scheduler")
    .Date(new DateTime(2013, 6, 13))
    .StartTime(new DateTime(2014, 4, 13, 7, 00, 00))
    .Height(600)
    .Views(views => {
        views.DayView();
        views.WeekView(weekView => weekView.Selected(true));
        views.MonthView();
        views.AgendaView();
        views.CustomView("kendo.ui.ToDoView", view => view.Title("To Do").Selected(true));
    })
    .DataSource(d => d
        .Events(e => e.Error("error_handler"))
    // .Read("Meetings_Read", "Home")
    )
    )

**My Javascript:it is not OK**

    $.ajax(
         {
             url: '@Url.Action("Meetings_Read","Home")',
               cache: false,
               async: true,
               success: function (result) {
                   var scheduler = $("#scheduler").data("kendoScheduler");
                   var dataSource = new kendo.data.SchedulerDataSource({
                        data: result.Data
                   });
                 scheduler.setDataSource(dataSource);
              }
         });

**My Model:can bind to the scheduler,but can not show the title**

       public class SchedulerTest: ISchedulerEvent
    {
        
        public string Description { get; set; }

        public DateTime End { get; set; }

        public string EndTimezone { get; set; }

        public bool IsAllDay { get; set; }

        public string RecurrenceException { get; set; }

        public string RecurrenceRule { get; set; }

        public DateTime Start { get; set; }

        public string StartTimezone { get; set; }
        public string Title { get; set; }
    }

**My Controller:just show the title of everyday in a month**

     public virtual JsonResult Meetings_Read([DataSourceRequest] DataSourceRequest request)
     {
     return Json(meetingService.GetAll().ToDataSourceResult(request));
     }
       public List<SchedulerTest> GetAll()
        {
            var firstDate = DateTime.Now.Date.AddDays(1 - DateTime.Now.Day);
            var lastDate = firstDate.AddMonths(1);
            var schedulerTests= new List<SchedulerTest>();
            int i = 0;
            for (; firstDate < lastDate; firstDate = firstDate.AddDays(1))
            {
                schedulerTests.Add(new SchedulerTest
                {
                    Title = firstDate.ToString("yyMMdd") + "abc",
                    Start = firstDate,
                    End = firstDate.AddDyas, 
                });
            }

            return schedulerTests;
        }

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 29 Apr 2014, 07:35 AM
Hi,

We are not sure what "it is not ok" means in this context. What is the outcome of your code? Are there any JS errors? Right now we are not sure what the problem is and how to help you.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeff
Top achievements
Rank 1
answered on 02 May 2014, 08:28 PM
I'm not sure it's what you want, but my read looks like:

​self.ReadAjax = function(options) {
 $.ajax({
  url: "SiteEvents/ReadEvents",
  data: { siteKey: self.Site.Key() },
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(result) {
   console.log("Read Events " + result.length);
   ko.utils.arrayForEach(result, function(task) {
    console.log("Start:" + task.Start + " " + task.StartTimezone + " End:" + task.End + " Owner:" + task.OwnerId );
   });
   options.success(result);
  },
  error: function(result) {
   options.error(result);
  }
 });
};

Then in the dataSource, transport, set read: self.ReadAjax

Hope it helps.
Tags
Scheduler
Asked by
xixi
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or