Timescale Customization in ASP.NET MVC Scheduler

The time slots are usually the time cells that are displayed on the Day, Week, and Work Week views of both the calendar (in the leftmost position) and timeline views (at the top). The TimeScale property lets you control and set the required time slot duration for the work cells displayed on the Scheduler. It includes the following sub-options:

  • Enable - When set to true, allows the Scheduler to display appointments accurately against the exact time duration. If set to false, all the appointments of a day are displayed one below the other with no grid lines. Its default value is true.
  • Interval – Defines the duration on which the time axis is displayed, for example, in 1 hour or 30 minute intervals. It accepts values in minutes and defaults to 60.
  • SlotCount – Decides the number of slots to be split for the specified time interval duration. It defaults to 2, thus displaying two slots to represent an hour (each slot representing 30 minutes).

Note: The upper limit for rendering slots within a single day, using the Interval and SlotCount properties of the TimeScale, is 1000. This constraint aligns with the maximum colspan value permissible for the table element, also capped at 1000. This restriction applies exclusively to the TimelineDay, TimelineWeek, and TimelineWorkWeek views.

Setting different time slot duration

The Interval and SlotCount properties can be used together on the Scheduler to set a different time slot duration, as shown in the following code example. Here, six time slots together represent an hour.

@using Syncfusion.EJ2.Schedule

@(Html.EJS().Schedule("schedule")
    .Width("100%")
    .Height("550px")
    .SelectedDate(new DateTime(2018, 2, 15))
    .Views(view => {
        view.Option(View.Day).Add();
        view.Option(View.Week).Add();
        view.Option(View.WorkWeek).Add();
    })
    .TimeScale(ts => ts.Enable(true).Interval(60).SlotCount(6))
    .EventSettings(new ScheduleEventSettings { DataSource = ViewBag.datasource })
    .Render()
)
public ActionResult Index()
{
    ViewBag.datasource = GetScheduleData();
    return View();
}

public List<AppointmentData> GetScheduleData()
{
    List<AppointmentData> appData = new List<AppointmentData>();
    appData.Add(new AppointmentData
    { Id = 1, Subject = "Blue Moon Eclipse", StartTime = new DateTime(2023, 2, 13, 9, 30, 0), EndTime = new DateTime(2023, 2, 13, 11, 0, 0) });
    appData.Add(new AppointmentData
    { Id = 2, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2023, 2, 15, 9, 30, 0), EndTime = new DateTime(2023, 2, 15, 11, 0, 0) });
    return appData;
}
    
public class AppointmentData
{
    public int Id { get; set; }
    public string Subject { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}

Customizing time cells using a template

The TimeScale property also provides template options that allow customization of time slots:

  • MajorSlotTemplate - The template option to be applied for major time slots. The template accepts either a string or an HTMLElement as the template design, and the parsed design is displayed on the time cells. Time details can be accessed within this template.
  • MinorSlotTemplate - The template option to be applied for minor time slots. The template accepts either a string or an HTMLElement as the template design, and the parsed design is displayed on the time cells. Time details can be accessed within this template.
@using Syncfusion.EJ2.Schedule

@(Html.EJS().Schedule("schedule")
    .Width("100%")
    .Height("550px")
    .SelectedDate(new DateTime(2018, 2, 15))
    .Views(view => {
        view.Option(View.Day).Add();
        view.Option(View.Week).Add();
        view.Option(View.WorkWeek).Add();
    })
    .TimeScale(ts => 
        ts.Enable(true)
        .Interval(60)
        .SlotCount(6)
        .MajorSlotTemplate("#majorSlotTemplate")
        .MinorSlotTemplate("#minorSlotTemplate"
    ))
    .EventSettings(new ScheduleEventSettings { DataSource = ViewBag.datasource })
    .Render()
)

<script id="majorSlotTemplate" type="text/x-template">
    <div>${majorSlotTemplate(data.date)}</div>
</script>

<script id="minorSlotTemplate" type="text/x-template">
    <div style="text-align: right; margin-right: 15px">${minorSlotTemplate(data.date)}</div>
</script>

<script type="text/javascript">
    window.majorSlotTemplate = function (date) {
        var instance = new ej.base.Internationalization();
        return instance.formatDate(date, { skeleton: 'hm' });
    };
    window.minorSlotTemplate = function (date) {
        var instance = new ej.base.Internationalization();
        return instance.formatDate(date, { skeleton: 'ms' }).replace(':00', '');
    };
</script>
public ActionResult Index()
{
    ViewBag.datasource = GetScheduleData();
    return View();
}

public List<AppointmentData> GetScheduleData()
{
    List<AppointmentData> appData = new List<AppointmentData>();
    appData.Add(new AppointmentData
    { Id = 1, Subject = "Blue Moon Eclipse", StartTime = new DateTime(2023, 2, 13, 9, 30, 0), EndTime = new DateTime(2023, 2, 13, 11, 0, 0) });
    appData.Add(new AppointmentData
    { Id = 2, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2023, 2, 15, 9, 30, 0), EndTime = new DateTime(2023, 2, 15, 11, 0, 0) });
    return appData;
}
    
public class AppointmentData
{
    public int Id { get; set; }
    public string Subject { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}

Hiding the timescale

The grid lines that indicate the exact time duration can be enabled or disabled on the Scheduler by setting true or false to the Enable option within the TimeScale property. Its default value is true.

@using Syncfusion.EJ2.Schedule

@(Html.EJS().Schedule("schedule")
    .Width("100%")
    .Height("550px")
    .SelectedDate(new DateTime(2018, 2, 15))
    .Views(view => {
        view.Option(View.Day).Add();
        view.Option(View.Week).Add();
        view.Option(View.WorkWeek).Add();
    })
    .TimeScale(ts => ts.Enable(false))
    .EventSettings(new ScheduleEventSettings { DataSource = ViewBag.datasource })
    .Render()
)
public ActionResult Index()
{
    ViewBag.datasource = GetScheduleData();
    return View();
}

public List<AppointmentData> GetScheduleData()
{
    List<AppointmentData> appData = new List<AppointmentData>();
    appData.Add(new AppointmentData
    { Id = 1, Subject = "Blue Moon Eclipse", StartTime = new DateTime(2023, 2, 13, 9, 30, 0), EndTime = new DateTime(2023, 2, 13, 11, 0, 0) });
    appData.Add(new AppointmentData
    { Id = 2, Subject = "Milky Way as Melting pot", StartTime = new DateTime(2023, 2, 15, 9, 30, 0), EndTime = new DateTime(2023, 2, 15, 11, 0, 0) });
    return appData;
}
    
public class AppointmentData
{
    public int Id { get; set; }
    public string Subject { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}

Highlighting current date and time

By default, the Scheduler indicates the current date with a highlighted date header on all views and marks the system’s current time on specific views such as Day, Week, Work Week, Timeline Day, Timeline Week, and Timeline Work Week. To stop highlighting the current time indicator on Scheduler views, set false on the ShowTimeIndicator property, which defaults to true.

@using Syncfusion.EJ2.Schedule

@(Html.EJS().Schedule("schedule")
    .Width("100%")
    .Height("550px")
    .Views(view => {
        view.Option(View.Day).Add();
        view.Option(View.Week).Add();
        view.Option(View.WorkWeek).Add();
        view.Option(View.TimelineDay).Add();
        view.Option(View.TimelineWeek).Add();
        view.Option(View.TimelineWorkWeek).Add();
    })
    .ShowTimeIndicator(false)
    .Render()
)
public ActionResult Index()
{
    return View();
}

NOTE

You can refer to our ASP.NET MVC Scheduler feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET MVC Scheduler example to know how to present and manipulate data.