This example demonstrates how to implement a custom Go to Date dialog.
-
Call the SetGotoDateFormTemplateContent method to specify custom content for the Go to Date form. Add a single Calendar extension to the form.
settings.OptionsForms.SetGotoDateFormTemplateContent(c => { Html.DevExpress().Calendar(calendarSettings => { calendarSettings.Name = "calendar"; calendarSettings.Properties.ClientSideEvents.SelectionChanged = "OnCalendarSelectionChanged"; calendarSettings.Properties.ShowClearButton = false; }).Bind(c.Date).Render(); });
-
Specify the CalendarClientSideEvents.SelectionChanged property to subscribe to selection changes in the calendar. The event handler calls the ASPxClientScheduler.GoToDateFormApply method to initiate a callback to the server.
function OnCalendarSelectionChanged(s, e){ gotoDateCallback = true; scheduler.GoToDateFormApply(); }
-
Handle the MVCxSchedulerClientSideEvents.BeginCallback event to obtain a new date from the calendar and pass it to the server.
function OnSchedulerBeginCallback(s, e){ if(gotoDateCallback){ e.customArgs["NewDate"] = calendar.GetValueString(); gotoDateCallback = false; } }
-
Implement a special callback command to handle this request properly. Create a
DevExpress.Web.ASPxScheduler.Internal.GotoDateFormCallbackCommand
class successor and override itsParseParameters
andExecuteCore
methods. In theExecuteCore
method, call methods of the IDateTimeNavigationService interface to perform date navigation in the scheduler.public class MVCxSchedulerGotoDateFormCallbackCommand: GotoDateFormCallbackCommand { public MVCxSchedulerGotoDateFormCallbackCommand(MVCxScheduler control) : base(control) { } public new DateTime NewDate { get; protected set; } protected override void ParseParameters(string parameters) { string rawDate = HttpContext.Current.Request["NewDate"]; NewDate = DateTime.Parse(rawDate); } protected override void ExecuteCore() { IDateTimeNavigationService service = (IDateTimeNavigationService)Control.GetService(typeof(IDateTimeNavigationService)); if (service != null) service.GoToDate(NewDate); } }
-
Create a delegate method for the SchedulerSettings.BeforeExecuteCallback property to execute your custom command instead of the default command when the
GotoDateForm
command is queried for execution.settings.BeforeExecuteCallbackCommand = (sender, e) => { if(e.CommandId == SchedulerCallbackCommandId.GotoDateForm) e.Command = new MVCxSchedulerGotoDateFormCallbackCommand((MVCxScheduler)sender); };
(you will be redirected to DevExpress.com to submit your response)