Articles in this section
Category / Section

How to Group and Color-Code Appointments using Blazor Scheduler?

4 mins read

This article explains how to group your appointments by worker and color-code them by type in a timeline view using Syncfusion's Scheduler component. To achieve this, you can utilize the EventRendered event. This event is triggered each time an appointment is rendered, allowing for customization based on the appointment's properties.

<SfSchedule TValue="AppointmentData" Height="550px" @bind-SelectedDate="@CurrentDate">
    <ScheduleEvents TValue="AppointmentData" EventRendered="OnEventRendered"></ScheduleEvents>
    <ScheduleGroup Resources="@Resources"></ScheduleGroup>
    <ScheduleResources>
        <ScheduleResource TItem="ResourceData" TValue="int[]" DataSource="@WorkersData" Field="WorkerId" Title="Owner" Name="Workers" TextField="WorkerText" IdField="Id" AllowMultiple="true" ColorField="TypeColor"></ScheduleResource>
    </ScheduleResources>
    <ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings>
    <ScheduleViews>
        <ScheduleView Option="View.TimelineDay"></ScheduleView>
        <ScheduleView Option="View.TimelineWeek"></ScheduleView>
    </ScheduleViews>
</SfSchedule>

In the code behind, you can handle the OnEventRendered method to set the background color of the appointments based on their type:

public void OnEventRendered(EventRenderedArgs<AppointmentData> args)
{
    string color = GetTypeColor(args.Data.TypeId);
    Dictionary<string, object> attributes = new Dictionary<string, object>();
    attributes.Add("style", $"background-color: {color}");
    args.Attributes = attributes;
}
public string GetTypeColor(int typeId)
{
    string color = "";
    foreach (var item in TypeData)
    {
        if (item.Id == typeId)
        {
            color = item.TypeColor;
        }
    }
    return color;
}

Sample link:  https://blazorplayground.syncfusion.com/BNhpMMhZgkCLhqVv


Conclusion

I hope you enjoyed learning about how to group and color-code appointments using Blazor Scheduler.

You can refer to our Blazor Scheduler feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Scheduler example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied