Features
Uses DayPilot 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 sample project
C# source code of the sample included
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.
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);
}
}
Database Schema
Here is the database schema of the attached SQL Server database (daypilot.mdf):
CREATE TABLE [dbo].[event] (
[id] INT IDENTITY (1, 1) NOT NULL,
[name] VARCHAR (50) NULL,
[eventstart] DATETIME NOT NULL,
[eventend] DATETIME NOT NULL,
[resource] INT NOT NULL,
CONSTRAINT [PK_event] PRIMARY KEY CLUSTERED ([id] ASC)
);
CREATE TABLE [dbo].[resource] (
[id] INT IDENTITY (1, 1) NOT NULL,
[name] VARCHAR (50) NOT NULL
);