Skip to content

Commit 6333519

Browse files
ntachevadimodi
andauthored
[3.7.0] docs(scheduler): OnCellRender event (#1181)
* docs(scheduler): OnCellRender event - draft * docs(scheduler):fixes * Update components/scheduler/events.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> * Update components/scheduler/events.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com> * Update components/scheduler/events.md Co-authored-by: Dimo Dimov <961014+dimodi@users.noreply.github.com>
1 parent b49c038 commit 6333519

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

components/scheduler/events.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This article explains the events available in the Telerik Scheduler for Blazor:
1818
* [OnItemDoubleClick](#onitemdoubleclick)
1919
* [OnItemContextMenu](#onitemcontextmenu)
2020
* [ItemRender](#itemrender)
21+
* [OnCellRender](#oncellrender)
2122
* [DateChanged](#datechanged)
2223
* [ViewChanged](#viewchanged)
2324

@@ -939,6 +940,106 @@ Through its event arguments you can get the `Item` to cast it to your model type
939940
</style>
940941
````
941942

943+
## OnCellRender
944+
945+
The `OnCellRender` event fires upon rendering of each slot cell. It allows you to set a custom CSS class to the cell, based on business logic.
946+
947+
The handler receives an argument of type `SchedulerCellRenderEventArgs` which exposes the following fields:
948+
949+
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
950+
951+
| Field | Type | Description |
952+
| --- | --- | --- |
953+
| `Class` | `string` | The CSS class that will be applied to the cell. |
954+
| `Date` | `DateTime` | The date that is associated with the cell. |
955+
| `IsAllDay` | `bool` | Whether the slot is inside the `AllDay` row/column.
956+
| `Resources` | `List<KeyValuePair<string, object>` | The resources that are associated with the column/row. Applicable when the Scheduler uses both - [resources]({%slug scheduler-resources%}) and [grouping]({%slug scheduler-resource-grouping%}). Needed to differentiate between the same dates within different groups. |
957+
| `SlotStartTime` | `DateTime` | The slot start time. The date is 1/1/1900, but the essential part is the time portion. |
958+
| `SlotEndTime` | `DateTime` | The slot end time. The date is 1/1/1900, but the essential part is the time portion. |
959+
960+
961+
````CSHTML
962+
<style>
963+
.lunch-break {
964+
background-color: rgba(255,124,115,0.3);
965+
}
966+
967+
.lunch-break::after {
968+
content: "Lunch break";
969+
}
970+
</style>
971+
972+
<TelerikScheduler Data="@Appointments"
973+
OnCellRender="@OnCellRenderHandler"
974+
@bind-Date="@SchedulerStartDate"
975+
@bind-View="@SchedulerCurrentView"
976+
Height="600px">
977+
<SchedulerViews>
978+
<SchedulerDayView StartTime="@DayStart" EndTime="@DayEnd" />
979+
<SchedulerWeekView StartTime="@DayStart" EndTime="@DayEnd" />
980+
<SchedulerMonthView />
981+
</SchedulerViews>
982+
</TelerikScheduler>
983+
984+
@code {
985+
private DateTime SchedulerStartDate { get; set; } = new DateTime(2022, 7, 25, 8, 0, 0);
986+
987+
private SchedulerView SchedulerCurrentView { get; set; } = SchedulerView.Week;
988+
989+
// only the time portion matters
990+
private DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 8, 0, 0);
991+
private DateTime DayEnd { get; set; } = new DateTime(2000, 1, 1, 19, 0, 0);
992+
993+
private void OnCellRenderHandler(SchedulerCellRenderEventArgs args)
994+
{
995+
DateTime lunchStart = new DateTime(1900, 1, 1, 12, 0, 0);
996+
DateTime lunchEnd = new DateTime(1900, 1, 1, 12, 30, 0);
997+
998+
if ((args.SlotStartTime.Equals(lunchStart) || args.SlotEndTime.Equals(lunchEnd)) &&
999+
(args.Date.Value.DayOfWeek != DayOfWeek.Saturday && args.Date.Value.DayOfWeek != DayOfWeek.Sunday))
1000+
{
1001+
args.Class = "lunch-break";
1002+
}
1003+
}
1004+
1005+
private List<SchedulerAppointment> Appointments = new List<SchedulerAppointment>()
1006+
{
1007+
new SchedulerAppointment
1008+
{
1009+
Title = "Planning meeting",
1010+
Start = new DateTime(2022, 7, 25, 9, 0, 0),
1011+
End = new DateTime(2022, 7, 25, 11, 30, 0)
1012+
},
1013+
new SchedulerAppointment
1014+
{
1015+
Title = "Software updates",
1016+
Start = new DateTime(2022, 7, 26, 13, 0, 0),
1017+
End = new DateTime(2022, 7, 26, 14, 30, 0)
1018+
},
1019+
new SchedulerAppointment
1020+
{
1021+
Title = "Support meeting",
1022+
Start = new DateTime(2022, 7, 27, 8, 0, 0),
1023+
End = new DateTime(2022, 7, 27, 9, 30, 0)
1024+
},
1025+
new SchedulerAppointment
1026+
{
1027+
Title = "Trip to Hawaii",
1028+
IsAllDay = true,
1029+
Start = new DateTime(2022, 7, 28),
1030+
End = new DateTime(2022, 8, 07)
1031+
}
1032+
};
1033+
1034+
public class SchedulerAppointment
1035+
{
1036+
public string Title { get; set; }
1037+
public DateTime Start { get; set; }
1038+
public DateTime End { get; set; }
1039+
public bool IsAllDay { get; set; }
1040+
}
1041+
}
1042+
````
9421043

9431044
## DateChanged
9441045

0 commit comments

Comments
 (0)