Server Filtering of the Scheduler Events
Environment
Product | Telerik UI for ASP.NET Core Scheduler |
Product Version | Created with version 2024.4.1112 |
Description
How can I filter the events of the ASP.NET Core Scheduler 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 a Read request to the remote endpoint upon each navigation that occurs in the Scheduler.Razor@(Html.Kendo().Scheduler<TaskViewModel>() .Name("scheduler") ...// Additional configuration. .DataSource(dataSource => dataSource .ServerFiltering(true) ...// Additional configuration. ) )
-
Set the
Data()
option to the Read request configuration and add a handler that will send the start and end dates of the visible range of the Scheduler to the server. This will occur when the Read action is triggered.Razor@(Html.Kendo().Scheduler<TaskViewModel>() .Name("scheduler") ...// Additional configuration. .DataSource(dataSource => dataSource .ServerFiltering(true) .Read(read => read.Action("Read", "Home").Data("getAdditionalData")) .Create("Create", "Home") .Destroy("Destroy", "Home") .Update("Update", "Home") ...// Additional configuration. ) )
-
Create a
FilterRange
Model to ensure the received date range is parsed correctly. Define the setters of thestart
andend
properties to convert the dates to UTC.FilterRange.csusing 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
FilterRange
in theRead
Action and return the filtered events data to the Scheduler.HomeController.cspublic virtual JsonResult Read(DataSourceRequest request, FilterRange range) { var data = taskService.GetRange(range.Start, range.End); return Json(data.ToDataSourceResult(request)); }
For a runnable example, refer to the ASP.NET MVC application in the UI for ASP.NET MVC Examples repository. You can use this as a starting point to configure the same behavior in an ASP.NET Core project.