Scheduler Recurrence
The Telerik Scheduler for Blazor supports displaying and editing of recurring appointments and exceptions. This article describes how to:
- Configure the Scheduler for using recurring appointments.
- Define recurrence rules and recurrence exceptions in the Scheduler data.
- Edit recurring appointments and exceptions.
- Handle editing and deleting recurring appointments with the recurrence context.
Basics
To display recurring appointments in the Scheduler component, the model class must implement three recurrence-related properties:
RecurrenceRuleRecurrenceExceptionsRecurrenceId
You can also define custom property names through the respective Scheduler parameters:
RecurrenceRuleFieldRecurrenceExceptionsFieldRecurrenceIdField
A single Scheduler data item defines one series of recurring appointments. Set the RecurrenceRule value, according to the RFC5545 standard, except for a known discrepancy with extra hyphens in UNTIL. Then, if exceptions to the recurrence rule exist:
- Each exception must be a separate data item.
- The
RecurrenceIdproperty of each exception must be equal toIdvalue of the recurring appointment. - The
RecurrenceExceptionsproperty of the recurring appointment must contain theStartvalues of all occurrences, which are exceptions to the recurrence rule. The correct values are the original startDateTimevalues of the occurrences, which would apply if there were no exceptions.
Telerik UI for Blazor version 15.0.0 introduced a revised built-in recurrence editing UI.
Example
Bind Scheduler to recurring appointments and recurrence exceptions
Handling Recurring Appointments in CRUD Events
When users edit, update, or delete a recurring appointment, the Scheduler prompts them to choose whether to modify only the current occurrence or the entire series. The OnEdit, OnUpdate, and OnDelete event handlers receive event arguments that include an EditMode property. This property indicates the user's choice when interacting with recurring appointments:
SchedulerRecurrenceEditMode.Series—The user chose to edit or delete the entire series of recurring appointments.SchedulerRecurrenceEditMode.Occurrence—The user chose to edit or delete only a single occurrence of the recurring appointment.
Example
You can use the EditMode property to implement different logic based on whether the user is modifying a single occurrence or the entire series.
Handle RecurrenceEditMode in OnUpdate and OnDelete events
Important Considerations
- When the user edits or deletes a single occurrence of a recurring appointment, the Scheduler automatically manages the
RecurrenceExceptionslist and creates exception appointments with the appropriateRecurrenceId. - The
RecurrenceEditModeproperty is only relevant when working with recurring appointments. For regular (non-recurring) appointments, this property is not used. - When creating a new appointment in a time slot that matches a recurring appointment, the user can choose to create an exception or a new independent appointment.
Recurrence Editor Components
Telerik UI for Blazor provides standalone components that you can use to edit recurring appointments outside the Scheduler or in a custom Scheduler popup edit form. Telerik UI for Blazor version 15.0.0 introduced a revised built-in recurrence editing UI, but the previously exposed standalone recurrence editors continued working as before.
The Telerik Blazor recurrence editor components include:
| Component Name | Renders As | Description |
|---|---|---|
RecurrenceFrequencyEditor | Button Group | Defines whether the appointment repeats daily, weekly, monthly, yearly, or never. |
RecurrenceIntervalEditor | Numeric TextBox | Defines whether the appointment repeats in each period (for example, every day), or skips periods (for example, once in three days). |
RecurrenceEditor | Button Group or Radio Group |
|
RecurrenceEndEditor | Radio Group, Numeric TextBox, Date Picker | Defines if the appointment repeats indefinitely, a number of times, or until a specific date. |
Parameters
All recurrence editor components expose:
- A
Ruleparameter of typeTelerik.Recurrence.RecurrenceRulethat supports two-way binding. - A
RuleChangedevent that receives aRecurrenceRuleargument. - A
Classparameter for styling customizations.
In addition:
- The
RecurrenceIntervalEditorsupports anIdparameter of typestring. Use it to set a customidattribute to the Numeric TextBox and the sameforattribute to the associated Repeat every label. - The
RecurrenceEndEditorsupports anEndparameter of typeDateTime. Use it to set a default value for the End On Date Picker when there is noUNTILsetting in the recurrence rule string.
Recurrence Rule Type Conversion
Use the following methods to convert from RFC5545 strings to RecurrenceRule objects and vice-versa:
- The static method
RecurrenceRule.Parse()to convert from RFC5545stringtoRecurrenceRule. - The instance method
RecurrenceRule.ToString()to convert fromRecurrenceRuleto a RFC5545string.
Converting between different recurrence rule formats
// RFC5545 string
string recurrenceString = "FREQ=WEEKLY;BYDAY=MO,WE,FR";
// Convert to RecurrenceRule
RecurrenceRule recurrenceRule = RecurrenceRule.Parse(recurrenceString);
// Make some changes...
// Convert to RFC5545 string
string newRecurrenceString = recurrenceRule.ToString();
Telerik Form Integration
There are two recommended ways to use the Telerik recurrence editors in a Telerik Form:
- Place each recurrence editor in a separate Form item
Template. This is the simpler option to set up. - Place all recurrence editors in a
<FormItemsTemplate>. This is a more verbose approach, which provides better control over the Form's HTML rendering, layout and styling.
The following examples can serve as a reference for creating custom Telerik Scheduler edit forms with recurrence editing. Using a markup structure that differs from the ones below may produce unexpected layouts.
Using Telerik recurrence editors in separate Form item templates
To add the recurrence editors to a FormItemsTemplate, follow the same approach as in the example above, but add the following <FormItemsTemplate> tag as a child of <TelerikForm>.
Using Telerik recurrence editors in a FormItemsTemplate
<FormItemsTemplate Context="formContext">
@{
var formItems = formContext.Items.Cast<IFormItem>().ToList();
}
<TelerikFormItemRenderer Item="@( formItems.First(x => x.Field == nameof(Appointment.Title)) )" />
<TelerikFormItemRenderer Item="@( formItems.First(x => x.Field == nameof(Appointment.Start)) )" />
<TelerikFormItemRenderer Item="@( formItems.First(x => x.Field == nameof(Appointment.End)) )" />
<TelerikFormItemRenderer Item="@( formItems.First(x => x.Field == nameof(Appointment.RecurrenceRule)) )" />
<div class="k-form-field">
<TelerikRecurrenceFrequencyEditor Rule="@Rule"
RuleChanged="@OnRuleChanged" />
</div>
@if (Rule != null)
{
<div class="k-form-field">
<TelerikRecurrenceIntervalEditor Rule="@Rule" />
</div>
}
<div class="k-form-field">
<TelerikRecurrenceEditor Rule="@Rule"
RuleChanged="@OnRuleChanged" />
</div>
@if (Rule != null)
{
<div class="k-form-field">
<TelerikRecurrenceEndEditor Rule="@Rule"
EndDate="@RecurrenceEndDefaultDate" />
</div>
}
</FormItemsTemplate>