Files to look at:
- SchedulerController.cs
- SchedulerExtensionHelper.cs
- SchedulingDataClasses.cs
- Scheduler.cshtml
- SchedulerPartial.cshtml
Scheduler - How to customize the Go to Date dialog
This sample project illustrates how you can invoke a custom form instead of the standard Go to Date dialog and implement the functionality that enables the end-user to navigate dates using the custom form.
The technique utilized in this example is briefly explained below.
Let's start with the custom form.
The custom form consists of a single Calendar control. Its settings are specified via the CalendarSettings properties.
The SchedulerSettings.OptionsForms.SetGotoDateFormTemplateContent method is used to include a rendered custom form into the SchedulerPartial view.
To handle date selection within the Calendar control, we subscribe to the corresponding client-side event using the CalendarClientSideEvents.SelectionChanged property.
The event handler toggles the value of the boolean gotoDateCallback variable that indicates whether a special processing is required on a scheduler callback. Then the client-side ASPxClientScheduler.GoToDateFormApply method is called that initiates a callback to pass form data to the server control.
To handle a scheduler callback, we subscribe to the BeginCallback client-side event of the Scheduler. The SchedulerSettings.ClientSideEvents.BeginCallback property specifies the name of the handler function.
If the gotoDateCallback indicator is turned on, the function obtains new date from the calendar located in the custom form and passes it on to the callee.
To handle this request properly, we need a specialized callback command. We inherit this command from the DevExpress.Web.ASPxScheduler.Internal.GotoDateFormCallbackCommand class and override its ParseParameters and ExecuteCore methods. To register this command so it is executed instead of the default GotoDateFormCallbackCommand, the SchedulerSettings.BeforeExecuteCallbackCommand property is used. It specifies a custom handler that switches command execution when the command with the SchedulerCallbackCommandId.GotoDateForm identifier is queried for execution.
Finally, within the ExecuteCore method of a custom MVCxSchedulerGotoDateFormCallbackCommand command, methods of the IDateTimeNavigationService interface are called to perform date navigation within the scheduler.
When the application runs, select the Go to Date in the context menu. The result is shown in the picture below.