Search results

Getting started with Blazor Scheduler component

This section briefly explains about how to include a simple Scheduler in your Blazor server-side application. You can refer Getting Started with Syncfusion Blazor for Server-Side in Visual Studio 2019 page for the introduction and configuring the common specifications.

To get start quickly with Blazor Scheduler, you can check on this video:

Importing Syncfusion Blazor component in the application

  1. Install Syncfusion.Blazor NuGet package to the application by using the NuGet Package Manager.
  2. You can add the client-side style resources through CDN or from NuGet package in the <head> element of the ~/Pages/_Host.cshtml page.
   <head>
       ...
           <link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
           @*<link href="https://cdn.syncfusion.com/blazor/18.2.59/styles/bootstrap4.css" rel="stylesheet" />*@
       ...
   </head>

For Internet Explorer 11 kindly refer the polyfills. Refer the documentation for more information.

   <head>
       ...
           <link href="https://cdn.syncfusion.com/blazor/18.2.59/styles/bootstrap4.css" rel="stylesheet" />
           <script src="https://github.com/Daddoon/Blazor.Polyfill/releases/download/3.0.1/blazor.polyfill.min.js"></script>
       ...
   </head>

Adding component package to the application

Open ~/_Imports.razor file and import the Syncfusion.Blazor.Schedule package.

    @using Syncfusion.Blazor.Schedule

Add SyncfusionBlazor service in Startup file

Open the Startup.cs file and add services required by Syncfusion components using services.AddSyncfusionBlazor() method. Add this method in the ConfigureServices function as follows.

using Syncfusion.Blazor;

namespace BlazorApplication
{
    public class Startup
    {
        ....
        ....
        public void ConfigureServices(IServiceCollection services)
        {
            ....
            ....
            services.AddSyncfusionBlazor();
        }
    }
}

To enable custom client side resource loading from CRG or CDN. You need to disable resource loading by AddSyncfusionBlazor(true) and load the scripts in the HEAD element of the ~/Pages/_Host.cshtml page.

   <head>
       ...
           <link href="https://cdn.syncfusion.com/blazor/18.2.59/styles/bootstrap4.css" rel="stylesheet" />
           <script src="https://cdn.syncfusion.com/blazor/18.2.59/syncfusion-blazor.min.js"></script>
       ...
   </head>

Initialize the Scheduler component

The Scheduler component can be rendered on the page by defining the SfSchedule tag helper. Add the following code example to your index.razor page which is available within the ~/Pages/ folder, to initialize the Scheduler component.

@using Syncfusion.Blazor.Schedule

<SfSchedule TValue=object></SfSchedule>

The output of the above code will display the empty scheduler as shown in the following image.

Empty Scheduler

Populating appointments

  • To populate the Scheduler with appointments, bind the event data to it by assigning the DataSource property under ScheduleEventSettings.
@using Syncfusion.Blazor.Schedule

<SfSchedule TValue="AppointmentData" Height="650px" SelectedDate="@(new DateTime(2020, 2, 14))">
    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings>
</SfSchedule>

@code{
    List<AppointmentData> DataSource = new List<AppointmentData>
    {
        new AppointmentData { Id = 1, Subject = "Paris", StartTime = new DateTime(2020, 2, 13, 10, 0, 0) , EndTime = new DateTime(2020, 2, 13, 12, 0, 0) },
        new AppointmentData { Id = 2, Subject = "Germany", StartTime = new DateTime(2020, 2, 15, 10, 0, 0) , EndTime = new DateTime(2020, 2, 15, 12, 0, 0) }
    };
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

The scheduler with the appointments will be rendered as shown in the following image.

Scheduler with appointments

Setting date

The Scheduler usually displays the system date as its current date. To change the current date of Scheduler with specific date, define the SelectedDate property.

@using Syncfusion.Blazor.Schedule

<SfSchedule TValue="AppointmentData" Height="650px" SelectedDate="@(new DateTime(2020, 1, 10))">
</SfSchedule>

@code{
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

Setting view

The Scheduler displays Week view by default. To change the current view, define the applicable view name to the CurrentView property. The applicable view names are,

  • Day
  • Week
  • WorkWeek
  • Month
  • Agenda
  • MonthAgenda
  • TimelineDay
  • TimelineWeek
  • TimelineWorkWeek
  • TimelineMonth
  • TimelineYear
  • Year
@using Syncfusion.Blazor.Schedule

<SfSchedule TValue="AppointmentData" Height="650px" CurrentView="View.Month">
</SfSchedule>

@code{
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

Individual view customization

Each individual Scheduler views can be customized with its own options such as setting different start and end hour on Week and Work Week views, whereas hiding the weekend days on Month view alone which can be achieved by defining the ScheduleView.

@using Syncfusion.Blazor.Schedule

<SfSchedule TValue="AppointmentData" Height="650px" SelectedDate="@(new DateTime(2020, 2, 13))">
    <ScheduleViews>
        <ScheduleView Option="View.Week" StartHour="07:00" EndHour="15:00"></ScheduleView>
        <ScheduleView Option="View.WorkWeek" StartHour="10:00" EndHour="18:00"></ScheduleView>
        <ScheduleView Option="View.Month" ShowWeekend="false"></ScheduleView>
    </ScheduleViews>
</SfSchedule>

@code{
    public class AppointmentData
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }
}

See Also

  1. Getting Started with Syncfusion Blazor for client-side in .NET Core CLI
  2. Getting Started with Syncfusion Blazor for client-side in Visual Studio 2019
  3. Getting Started with Syncfusion Blazor for server-side in .NET Core CLI