Search code examples
entity-frameworkschedulerdhtmlx-scheduler

dhtmlx scheduler and entity framework


Hi I am using dhtmlx scheduler with mvc razor.

I have create the units tab. But i am not getting how to divide the events across different units. Here is my sample code.

Scheduler.InitialDate = DateTime.Now.Date;// the initial data of Scheduler   
       var unit = new UnitsView("Employee", "EmpID");//initializes the view
       var rooms = new List<object>(){
            new { key = "1", label = "Employee1"},
            new { key = "2", label = "Employee2"},
            new { key = "3", label = "Employee3"},
            new { key = "4", label = "Employee4"}
              };
          unit.AddOptions(rooms);

        Scheduler.Views.Add(unit);

I need to add the label from the database, I get the ID and display name through a stored procedure,Please help me displaying it in the scheduler unitsview. I use entity database first in mvc3 razor

Update:

 var unit = new UnitsView("units", "resourcename");
            scheduler.Views.Add(unit);
              List<GetResourceOrderDisplay_Result> resourcedisplayname = new List<GetResourceOrderDisplay_Result>();
              resourcedisplayname = _scheduler.Getresorderdisplay();
            DashboardViewModel objDashboardViewModel = new DashboardViewModel();
             var options = new List<object>();
          //how to add key and label from the result i'm getting from resourcedisplayname?

            unit.AddOptions(options);

>

 public partial class GetResourceOrderDisplay_Result
    {
        public int ID { get; set; }
        public string DisplayName { get; set; }
    }

model:

public class DashboardViewModel
    {


        //scheduler unitsview
        public int ID { get; set; }
        public string DisplayName { get; set; }
    }

this is where I get Id and display name from the storedprocedure

 public List<GetResourceOrderDisplay_Result> Getresorderdisplay()
        {
            List<GetResourceOrderDisplay_Result> oGetresorderdisplay = new List<GetResourceOrderDisplay_Result>();

            oGetresorderdisplay = dbContext.GetResourceOrderDisplay().ToList();

            return oGetresorderdisplay.ToList();
        }

Solution

  • But i am not getting how to divide the events across different units

    Second parameter of units view constructor specifies the property of the data item that holds the relation. In your code

    var unit = new UnitsView("Employee", "EmpID");//initializes the view
    var rooms = new List<object>(){
        new { key = "1", label = "Employee1"},
        new { key = "2", label = "Employee2"},
        new { key = "3", label = "Employee3"},
        new { key = "4", label = "Employee4"}
    };
    

    Scheduler will check value of eventObj.EmpID property of your events and will be placing events inside the columns with equal value of the 'key' property. Event with EventObj.EmpID == "2" will be placed inside the second column.

    I need to add the label from the database,

    UnitsView has a public Label property

    var unit = new UnitsView("Employee", "EmpID");
    unit.Label = "label";
    

    UPDATE

    if you use model class with a different properties, you still can collect values for a units view with IEnumerable.Select :

    var unit = new UnitsView("Employee", "EmpID");
    
    List<GetResourceOrderDisplay_Result> resourcedisplayname = new List<GetResourceOrderDisplay_Result>();
    resourcedisplayname = _scheduler.Getresorderdisplay();
    
    unit.AddOptions(resourcedisplayname.Select(u => new {key=u.ID, label=u.DisplayName}));