Displaying events for timeline


I’ve searched the forum but nothing seems to work for my problem. I’m already able to initialize my y_units from my DB. I’m now supposed to display the events for my y_units. I’m using the _debug.js. A popup appears whenever I load the page, but the cell is always empty. When I look at the response here’s what I receive:

<data> <event id="1"> <start_date><![CDATA[02/23/2012 00:00]]></start_date> <end_date><![CDATA[02/29/2012 23:59]]></end_date> <text><![CDATA[Morning Shift]]></text> </event> </data>

Here’s my Data.cshtml

@{ Layout = null; } @model IEnumerable<LivePOS.Payroll.ViewModels.MyViewModel> <data> @foreach (var myevent in Model) { <event id="@myevent.id"> <start_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.start_date)]]></start_date> <end_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.end_date)]]></end_date> <text><![CDATA[@myevent.text]]></text> </event> } </data>

here’s my jscript:

[code]function init() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

        scheduler.config.xml_date = "%m/%d/%Y %H:%i";            
            section_autoheight: false,
            name: "matrix",
            x_unit: "day",
            x_date: "%d %M",
            x_step: 1,
            x_size: 7,
            x_length: 7,
            x_start: 0,
                    @foreach (var sched in Model) {
                                { key: @(sched.EmployeeId), label: "@(sched.FullName)" },
            y_property: "id",
            render: "cell"
        scheduler.templates["matrix_cell_value"] = function (ar) { // ar = array of events for that cell or undefined
            if (ar) { // there are some events
                text = '';
                for (var i = 0; i < ar.length; i++)
                    text += "<p>" + ar[i].text + "</p>";
                return text;
            return "";
        scheduler.init("scheduler_here", new Date(y, m, d), "matrix");

        var dp = new dataProcessor("/Calendar/Save");
        dp.setTransactionMode("POST", false);

Hope someone can look at my code and pinpoint what has gone wrong.
Thank you :slight_smile:

Check incorrect-xml section
docs.dhtmlx.com/doku.php?id=othe … mon_errors

It looks as missed content type, you need to add some instruction, to specify content type of output - it must be text/xml

Hi Stanislav,

I updated my Data.cshtml with:

@{ Layout = null; Response.ContentType = "text/xml"; } @model IEnumerable<LivePOS.Payroll.ViewModels.MyViewModel> <data> @foreach (var myevent in Model) { <event id="@myevent.id"> <start_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.start_date)]]></start_date> <end_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.end_date)]]></end_date> <text><![CDATA[@myevent.text]]></text> </event> } </data>

but still is not able to parse the response.

are you still getting alert after you defined content type?
Your Data.cshtml works for me, but i’m not sure that scheduler’s configuration is correct

y_property: "id",
  • you should use event property that contains employee id, since you use it as key of timeline units

so your data may look like

<event id="@myevent.id"> <start_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.start_date)]]></start_date> <end_date><![CDATA[@String.Format("{0:MM/dd/yyyy HH:mm}",myevent.end_date)]]></end_date> <text><![CDATA[@myevent.text]]></text> <employeeId><![CDATA[@myevent.employeeId]]></employeeId> </event>
and config

y_property: "employeeId",

Thank you! That worked. We’ll definitely buy a license if support is this good :slight_smile:

i have written the following code in mvc aspx if i tried to convert it into razor then it promt me
“load xml error”
pls help me
this is my data view

@foreach(var myevent in Model) { }

this is my only controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MyCalendar.Controllers
public class CalendarActionResponseModel
public String Status;
public Int64 Source_id;
public Int64 Target_id;

    public CalendarActionResponseModel(String status, Int64 source_id, Int64 target_id)
        Status = status;
        Source_id = source_id;
        Target_id = target_id;

public class CalendarController : Controller
    // GET: /Calendar/

    public ActionResult Index()
        return View();

    public ActionResult Data()
        DataClasses1DataContext data = new DataClasses1DataContext();
        return View(data.Events);

    public ActionResult Save(Event changedEvent, FormCollection actionValues)
        String action_type = actionValues["!nativeeditor_status"];
        Int64 source_id = Int64.Parse(actionValues["id"]);
        Int64 target_id = source_id;

        DataClasses1DataContext data = new DataClasses1DataContext();
            switch (action_type)
                case "inserted":
                case "deleted":
                    changedEvent = data.Events.SingleOrDefault(ev => ev.id == source_id);
                default: // "updated"
                    changedEvent = data.Events.SingleOrDefault(ev => ev.id == source_id);
            target_id = changedEvent.id;
            action_type = "error";

        return View(new CalendarActionResponseModel(action_type, source_id, target_id));


my index page

ViewBag.Title = “Index”;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <script src="/Scripts/dhtmlxscheduler.js" type="text/javascript"></script>
    <link href="/Scripts/dhtmlxscheduler.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        html, body
    <script type="text/javascript">
        $('#scheduler_here').ready(function () 
            scheduler.config.xml_date = "%m/%d/%Y %H:%i";
            scheduler.init("scheduler_here", new Date(2010, 6, 1), "month");
            var dp = new dataProcessor("/Calendar/Save");
            dp.setTransactionMode("POST", false);

	<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
		<div class="dhx_cal_navline">
			<div class="dhx_cal_prev_button">&nbsp;</div>
			<div class="dhx_cal_next_button">&nbsp;</div>
			<div class="dhx_cal_today_button"></div>
			<div class="dhx_cal_date"></div>
			<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
			<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
			<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
		<div class="dhx_cal_header">
		<div class="dhx_cal_data">

my save view

@model calender.Models.CalendarActionResponseModel

ViewBag.Title = “Save”;

same code in mvc(aspx) working properly
i dnt understand whats problem

did you specify content type of Data and Save views?
here is a working sample,which may help
support.dhtmlx.com/x-files/sampl … arMVC3.zip