Configuring the Scheduler with SignalR DataSource and Server Filtering
Environment
| Product | Telerik UI for ASP.NET MVC Scheduler |
| Product Version | Created with version 2024.4.1112 |
Description
How can I filter the events of the ASP.NET MVC Scheduler that uses SignalR DataSource on the server based on the selected date range in the current view?
Solution
-
Enable the
ServerFiltering()option of the DataSource in the Scheduler. This way, the component automatically sends areadcall to the local hub (service) upon each navigation that occurs in the Scheduler.Razor@(Html.Kendo().Scheduler<MeetingViewModel>() .Name("scheduler") ...// Additional configuration. .DataSource(dataSource => dataSource .SignalR() .ServerFiltering(true) ...// Additional configuration. ) ) -
Specify the
ParameterMap()option to send the start and end dates of the visible range of the Scheduler to the server when a Read action occurs. In the case of Create, Update, or Destroy action, the function will only send the respective new, edited, or deleted event data.Razor@(Html.Kendo().Scheduler<MeetingViewModel>() .Name("scheduler") ...// Additional configuration. .DataSource(dataSource => dataSource .SignalR() .ServerFiltering(true) .Transport(tr => tr .ParameterMap("onMap") .Promise("hubStart") .Hub("meetingHub") .Client(c => c .Read("read") .Create("create") .Update("update") .Destroy("destroy")) .Server(s => s .Read("read") .Create("create") .Update("update") .Destroy("destroy"))) ...// Additional configuration. ) ) -
Create a
FilterRangeModel to ensure the received date range is parsed correctly. Define the setters of thestartandendproperties to convert the dates to UTC.C#using System; using System.Collections.Generic; using System.Linq; using System.Web; public class FilterRange { private DateTime start; public DateTime Start { get { return start; } set { start = value.ToUniversalTime(); } } private DateTime end; public DateTime End { get { return end; } set { end = value.ToUniversalTime(); } } } -
Intercept the parameter of type
FilterRangein theReadAction in theProductHub.csand return the filtered events data to the client.C#public class ProductHub : Hub { private SchedulerMeetingService meetingService; public ProductHub() { meetingService = new SchedulerMeetingService(new SampleEntities1()); } public IEnumerable<MeetingViewModel> Read(FilterRange range) { var result = meetingService.GetAll().Where(t => t.Start < range.End && (t.End > range.Start || t.RecurrenceRule != null)); return result; } }
For a runnable example, refer to the ASP.NET MVC application in the UI for ASP.NET MVC Examples repository.