New to Telerik UI for ASP.NET Core? Download free 30-day trial

Change the Background Color of an Event Dynamically in the Scheduler


Product Version 2024.1.130
Product Telerik UI for ASP.NET Core Scheduler


How can I change the color of the entire element of the Telerik UI for ASP.NET Core Scheduler component's events dynamically?


  1. Create a property within the Scheduler Model that will hold the Color field.
  2. Subscribe to the DataBound event of the Scheduler.
  3. Within the event handler, iterate over the event records and their DOM element counterparts and explicitly change their background color by using the jQuery css() method.
        .StartTime(new DateTime(2013, 6, 13, 7, 00, 00))
        .Events(events => events.DataBound("onDataBound"))
        .Views(views =>
            views.WorkWeekView(workWeekView =>
    <kendo-scheduler name="scheduler" 
            <view type="day"></view>
            <view type="week" selected="true"></view>
            <view type="month"></view>
            <view type="agenda"></view>
            <view type="timeline"></view>
        <scheduler-datasource type="DataSourceTagHelperType.Ajax" page-size="20"    server-operation="false" data="@data">
             <schema data="Data" total="Total" errors="Errors">
                <scheduler-model id="TaskID">
                        <field name="TaskID" type="number"></field>
                        <field name="title" from="Title" type="string"></field>
                        <field name="start" from="Start" type="date"></field>
                        <field name="end" from="End" type="date"></field>
                        <field name="description" from="Description" type="string"></field>
                        <field name="recurrenceId" from="RecurrenceID" type="number"    default-value=null></field>
                        <field name="recurrenceRule" from="RecurrenceRule" type="string" ></    field>
                        <field name="recurrenceException" from="RecurrenceException"    type="string"></field>
                        <field name="OwnerID" type="number" default-value="1"></field>
                        <field name="startTimezone" from="StartTimezone" type="string"></   field>
                        <field name="endTimezone" from="EndTimezone" type="string"></field>
                        <field name="isAllDay" from="IsAllDay" type="boolean"></field>
public class SchedulerModel : ISchedulerEvent
        public int TaskID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

        public string Color {get;set;} // Property that will be used in the DataBound event handler.

        private DateTime start;
        public DateTime Start
                return start;
                start = value.ToUniversalTime();

        public string StartTimezone { get; set; }

        private DateTime end;
        public DateTime End
                return end;
                end = value.ToUniversalTime();

        public string EndTimezone { get; set; }

        public string RecurrenceRule { get; set; }
        public int? RecurrenceID { get; set; }
        public string RecurrenceException { get; set; }
        public bool IsAllDay { get; set; }
        public int? OwnerID { get; set; }

        public Task ToEntity()
            return new Task
                TaskID = TaskID,
                Title = Title,
                Start = Start,
                StartTimezone = StartTimezone,
                End = End,
                EndTimezone = EndTimezone,
                Description = Description,
                RecurrenceRule = RecurrenceRule,
                RecurrenceException = RecurrenceException,
                RecurrenceID = RecurrenceID,
                IsAllDay = IsAllDay,
                OwnerID = OwnerID
        function onDataBound(e) {
            var view = this.view();
            var events = this.dataSource.view(); // 1. Gather the currently present events  in the view.
            var eventElement; // 2. Create Flag variables for the event DOM element and  event object representation.
            var event;
            for (var idx = 0, length = events.length; idx < length; idx++) { // 3. Iterate  over each of the event entries.
                event = events[idx];
                eventElement = view.element.find("[data-uid=" + event.uid + "]"); // 4.     Gather the DOM representation of the currently iterated event.
                // Set the background of the element.
                eventElement.css("background-color", event.Color); // 5. Change the color   based on the established color field coming from the event model.

To see a full implementation of the aforementioned approach refer to the following Telerik REPL examples:

More ASP.NET Core Scheduler Resources

See Also

In this article