asp.net-mvc-5dhtmlx-scheduler

How to fetch records from database and display as an event in DHTMLXScheduler Calendar


I am using DHTMLXScheduler in my MVC5 webapplication to add patient and get patient's appointment and displaying this in calendar but I am having trouble i am getting data from database but this records not getting added according to start_time and end_time.

Calendar Controller:

    public ActionResult Index()
            {
                var sched = new DHXScheduler(this);
                sched.Skin = DHXScheduler.Skins.Terrace;
                sched.LoadData = true;
                sched.EnableDataprocessor = true;
                sched.InitialDate = new DateTime(2016, 5, 5);
                sched.Config.xml_date = "%d-%M-%Y %g:%i:%s%A";
                return View(sched);
            }
            public ContentResult Data()
            {

                return (new SchedulerAjaxData(
                    new Entities().AppointmentsLogs.Select(e=> new { id = e.AppointmentId, start_date = e.StartTime.ToString(), end_date=e.EndTime, text = e.PatientName })
                    // .Select(e => new { e.id, e.text, e.start_date, e.end_date })

                    )
                 );
            }  

Index.cshtml:

<!DOCTYPE html>
<html>
<head>
    <title>DHXScheduler initialization sample</title>
    <style>
        body {
            background-color: #eee;
        }
    </style>
</head>
<body>
    <div  name="timeline_tab" style="height:700px;width:900px;margin:0 auto">
        @Html.Raw(Model.Render())
    </div>
</body>
</html>
<script src="~/scripts/dhtmlxScheduler/dhtmlxscheduler.js"></script>
<script src="~/scripts/dhtmlxScheduler/ext/dhtmlxscheduler_timeline.js"></script>

Solution

  • Looks like you send start and end dates in different formats:

    , start_date = e.StartTime.ToString(), end_date=e.EndTime,

    StartTime is converted to string using system culture https://msdn.microsoft.com/en-us/library/k494fzbf(v=vs.110).aspx , while the EndTime is passed as DateTime and serialized by scheduler helper.

    Does anything changes if you pass both dates as DateTime?

    new Entities()
       .AppointmentsLogs
       .Select(e=> new 
       { 
           id = e.AppointmentId,
           start_date = e.StartTime,
           end_date=e.EndTime,
           text = e.PatientName
       });