Skip to content

Commit e35a106

Browse files
kendo-botKB Botxristianstefanov
authored
Added new kb article scheduler-add-hyperlinks-in-appointments (#3282)
* Added new kb article scheduler-add-hyperlinks-in-appointments * chore(Scheduler): apply suggestions as per comments --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Hristian Stefanov <[email protected]>
1 parent fed4347 commit e35a106

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: How to Add Hyperlinks in Scheduler Appointments
3+
description: Learn how to add clickable hyperlinks in Scheduler appointments in UI for Blazor.
4+
type: how-to
5+
page_title: Making Links Clickable in Scheduler Appointment Descriptions
6+
meta_title: Make Links Clickable in Scheduler Appointment Descriptions
7+
slug: scheduler-kb-add-hyperlinks-in-appointments
8+
tags: scheduler, templates, appointments, hyperlinks
9+
res_type: kb
10+
ticketid: 1697204
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Scheduler for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
I want to add clickable hyperlinks in Scheduler appointments. Including plain URLs in the Description field without having to write full `<a>` tags would be good.
26+
27+
## Solution
28+
29+
To achieve clickable hyperlinks in Scheduler appointments, implement a method to automatically detect and convert plain URLs in the Description field into clickable links.
30+
31+
1. Use the [`ItemTemplate`](slug:scheduler-templates-appointment) of the Scheduler to customize appointment rendering.
32+
2. Apply a helper method to parse the Description field and convert plain URLs to clickable links.
33+
34+
Here’s an example:
35+
36+
````Razor
37+
<TelerikScheduler Data="@Appointments" @bind-Date="@StartDate" @bind-View="@CurrView" Height="600px" Width="800px">
38+
<ItemTemplate>
39+
@{
40+
var appointment = context as SchedulerAppointment;
41+
var formattedDescription = ConvertUrlsToLinks(appointment.Description);
42+
}
43+
<div style="padding: 10px;" @onclick:stopPropagation>
44+
@((MarkupString)formattedDescription)
45+
</div>
46+
</ItemTemplate>
47+
48+
<AllDayItemTemplate>
49+
@{
50+
var appointment = context as SchedulerAppointment;
51+
}
52+
@appointment.Title
53+
<span>
54+
Starts on @appointment.Start.Date.ToShortDateString()
55+
ends on @appointment.End.Date.ToShortDateString()
56+
</span>
57+
</AllDayItemTemplate>
58+
59+
<SchedulerViews>
60+
<SchedulerDayView StartTime="@DayStart" />
61+
<SchedulerWeekView StartTime="@DayStart" />
62+
<SchedulerMonthView>
63+
<ItemTemplate>
64+
@{
65+
var appointment = context as SchedulerAppointment;
66+
if (appointment.IsAllDay)
67+
{
68+
<span>@appointment.Title</span>
69+
}
70+
else
71+
{
72+
<div title="@appointment.Title" style="font-size: small">
73+
@appointment.Start.ToShortTimeString() to @appointment.End.ToShortTimeString()
74+
</div>
75+
}
76+
}
77+
</ItemTemplate>
78+
</SchedulerMonthView>
79+
</SchedulerViews>
80+
</TelerikScheduler>
81+
82+
@code {
83+
private DateTime StartDate { get; set; } = new DateTime(2019, 11, 29);
84+
private SchedulerView CurrView { get; set; } = SchedulerView.Week;
85+
private DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 8, 0, 0); // the time portion is important
86+
87+
private List<SchedulerAppointment> Appointments = new()
88+
{
89+
new SchedulerAppointment
90+
{
91+
Title = "Vet visit",
92+
Description = "Check this link: https://demos.telerik.com/blazor-ui/scheduler/templates",
93+
Start = new DateTime(2019, 11, 26, 11, 30, 0),
94+
End = new DateTime(2019, 11, 26, 12, 30, 0)
95+
},
96+
new SchedulerAppointment
97+
{
98+
Title = "Planning meeting",
99+
Description = "Details here: https://demos.telerik.com/blazor-ui/scheduler/events",
100+
Start = new DateTime(2019, 11, 25, 9, 30, 0),
101+
End = new DateTime(2019, 11, 25, 12, 45, 0),
102+
Icon = SvgIcon.ExclamationCircle
103+
},
104+
new SchedulerAppointment
105+
{
106+
Title = "Trip to Hawaii",
107+
Description = "Info at www.travelagency.com/hawaii",
108+
IsAllDay = true,
109+
Start = new DateTime(2019, 11, 27),
110+
End = new DateTime(2019, 12, 07)
111+
}
112+
};
113+
114+
public class SchedulerAppointment
115+
{
116+
public string Title { get; set; }
117+
public string Description { get; set; }
118+
public DateTime Start { get; set; }
119+
public DateTime End { get; set; }
120+
public bool IsAllDay { get; set; }
121+
public ISvgIcon Icon { get; set; }
122+
}
123+
124+
private string ConvertUrlsToLinks(string input)
125+
{
126+
if (string.IsNullOrWhiteSpace(input))
127+
return string.Empty;
128+
129+
// Regex to match URLs like http://, https://, or www.
130+
var urlPattern = @"((http|https):\/\/[^\s]+|www\.[^\s]+)";
131+
return System.Text.RegularExpressions.Regex.Replace(input, urlPattern, match =>
132+
{
133+
var url = match.Value;
134+
var href = url.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? url : "https://" + url;
135+
return $"<a href=\"{href}\" target=\"_blank\">{url}</a>";
136+
});
137+
}
138+
}
139+
````
140+
141+
## See Also
142+
- [Scheduler Appointment Templates](scheduler-templates-appointment)

0 commit comments

Comments
 (0)