Git Product home page Git Product logo

asp-net-mvc-scheduler-custom-go-to-date-dialog's Introduction

Scheduler for ASP.NET MVC - How to customize the Go to Date dialog

This example demonstrates how to implement a custom Go to Date dialog.

Implementation Details

  1. 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();
    });
  2. 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();
    }
    
  3. 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;
        }
    }
    
  4. Implement a special callback command to handle this request properly. Create a DevExpress.Web.ASPxScheduler.Internal.GotoDateFormCallbackCommand class successor and override its ParseParameters and ExecuteCore methods. In the ExecuteCore 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);
        }
    }
  5. 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);
    };

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.