Features

  • ASP.NET MVC 5 scheduler
  • Time on the horizontal axis
  • Resources (rooms, people, machines) on the vertical axis
  • Additional resource data in columns (Name, Id)
  • Clicking the column header sorts the resources
  • Visual Studio 2012 sample project
  • C# source code of the sample included
  • Includes a trial version of DayPilot Pro for ASP.NET MVC

License

Licensed for testing and evaluation purposes. You can use the source code of the tutorial if you are a licensed user of DayPilot Pro for ASP.NET MVC. Buy a license.

Scheduler Resource Header Columns

Create an ASP.NET MVC view with the scheduler. See also Scheduler for ASP.NET MVC tutorial for the setup instructions.

Define custom resource columns using HeaderColumns property:

@Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig
{
    BackendUrl = Url.Content("~/Scheduler/Backend"),
    ...
    HeaderColumns = new RowHeaderColumnCollection {
        new RowHeaderColumn("Name", 80),
        new RowHeaderColumn("Id", 80)
    }
})

Activating the Headers

Now we need to activate the column headers. We will modify the Column HTML to render a hyperlink with custom JavaScript action:

@Html.DayPilotScheduler("dps", new DayPilotSchedulerConfig
{
    BackendUrl = Url.Content("~/Scheduler/Backend"),
    ...
    HeaderColumns= new RowHeaderColumnCollection {
        new RowHeaderColumn("<a href='javascript:dps.commandCallBack(\"sort\", { field: \"name\" }); '>Name</a>", 80),
        new RowHeaderColumn("<a href='javascript:dps.commandCallBack(\"sort\", { field: \"id\" });'>Id</a>", 80)
    }
})

Reloading the Resources

Clicking the column header will fire Command event on the server side with "sort" as the command name and the sort column available in e.Data["field"]. 

protected override void OnCommand(CommandArgs e)
{
  switch (e.Command)
  {
    case "sort":
      LoadResources((string)e.Data["field"]);
      Update(CallBackUpdateType.Full);
      break;
  }
}

Full refresh is requested using Update(CallBackUpdateType.Full) call.

The LoadResources() method reloads the resources using the specified sort order:

private void LoadResources(string orderBy) {
  Resources.Clear();
  foreach (DataRow r in new EventManager().GetResources(orderBy).Rows)
  {
      Resource res = new Resource((string)r["name"], Convert.ToString(r["id"]));
      res.DataItem = r;
      Resources.Add(res);
  }
}