Skip to main content
A newer version of this page is available. .

How to: Customize Popup Menu

  • 5 minutes to read

PopupMenuCustomization

The page called DefaultItemWithCustomAction illustrates how to change the default action assigned to a menu item. It uses two different techniques to modify the existing menu.

One technique involves a JavaScript function defined in the page markup that replaces the default GoTo command with a custom handler. The ASPxScheduler.PopupMenuShowing event is handled to specify a JavaScript handler.

Another technique implements a CustomMenuViewCallbackCommand command that is used to perform a callback. The ASPxScheduler.BeforeExecuteCallbackCommand event should be handled to process the command. The ASPxScheduler.PopupMenuShowing event is handled to rename a menu item so it can be properly recognized by a custom callback command.

The code in the event handler changes the MenuItem.Name of the default New Appointment menu item to “MyNewAppointment” on the client side. The MenuItem.Text string that is displayed is changed to “Instant Appointment”. So, the popup menu displays the “Instant Appointment” text instead of the default text for the “New Appointment” command. When the user selects this item, a “MyNewAppointment” string is passed as a menu identifier to a callback command.

View Example

<script type="text/javascript">
    function DefaultViewMenuHandler(scheduler, s, args) {
        if (args.item.GetItemCount() <= 0) {
            if (args.item.name == "GotoToday") {
                if (window.confirm("Are you realy want to leave this day?")) {
                    scheduler.RaiseCallback("GOTODAY|" + args.item.name);
                }
            }
            else
                scheduler.RaiseCallback("MNUVIEW|" + args.item.name);
        }
    }
</script>
using DevExpress.Web;
using DevExpress.Web.ASPxScheduler;
using DevExpress.XtraScheduler;
    protected void ASPxScheduler1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
    {
        ASPxSchedulerPopupMenu menu = e.Menu;
        if (menu.MenuId.Equals(SchedulerMenuItemId.DefaultMenu)) {
            menu.ClientSideEvents.ItemClick = String.Format("function(s, e) {{ DefaultViewMenuHandler({0}, s, e); }}", ASPxScheduler1.ClientInstanceName);
            MenuItemCollection menuItems = menu.Items;
            MenuItem defaultItem = menuItems.FindByName("NewAppointment");
            defaultItem.Name = "MyNewAppointment";
            defaultItem.Text = "Instant Appointment";
        }
    }

 

To implement a new custom callback command, create a new class named CustomMenuViewCallbackCommand, which inherits from the DevExpress.Web.ASPxScheduler.Internal.MenuViewCallbackCommand class. The required functionality is implemented by overriding the ParseParameters and the ExecuteCore methods of the base class.

The code snippet below creates a new appointment in the selected interval with the “Busy” label (the Appointment.LabelId property is set to 1) and “Free” status (the Appointment.StatusId is set to the AppointmentStatusType.Busy value). This action is performed for menu items with the MenuItem.Name equal to “MyNewAppointment”. Use the ASPxScheduler.PopupMenuShowing event to set a menu item name.

To execute a custom callback command when the user clicks an item in the popup menu, handle the ASPxScheduler.BeforeExecuteCallbackCommand event and specify a custom callback command for the “MNUVIEW” value of the SchedulerCallbackCommandEventArgs.CommandId arguments property.

View Example

using DevExpress.Web;
using DevExpress.Web.ASPxScheduler;
using DevExpress.XtraScheduler;
    protected void ASPxScheduler1_BeforeExecuteCallbackCommand(object sender, SchedulerCallbackCommandEventArgs e) {
        if(e.CommandId == "MNUVIEW")
            e.Command = new CustomMenuViewCallbackCommand(ASPxScheduler1);
    }
public class CustomMenuViewCallbackCommand : DevExpress.Web.ASPxScheduler.Internal.MenuViewCallbackCommand {
    string menuItemName;

    public CustomMenuViewCallbackCommand(ASPxScheduler control)
        : base(control) {
    }

    public string MenuItemName { get { return menuItemName; } }

    protected override void ParseParameters(string parameters) {
        this.menuItemName = parameters;
        base.ParseParameters(parameters);
    }
    protected override void ExecuteCore() {
        ExecuteUserMenuCommand(MenuItemName);
        base.ExecuteCore();
    }
    protected internal virtual void ExecuteUserMenuCommand(string MenuItemName) {
        if(MenuItemName == "MyNewAppointment")
            CreateAppointment("New Appointment", AppointmentStatusType.Free, 1);
    }
    protected void CreateAppointment(string subject, AppointmentStatusType statusType, int labelId) {
        Appointment apt = Control.Storage.CreateAppointment(AppointmentType.Normal);
        apt.Subject = subject;
        apt.Start = Control.SelectedInterval.Start;
        apt.End = Control.SelectedInterval.End;
        apt.ResourceId = Control.SelectedResource.Id;
        apt.StatusKey = (int)statusType;
        apt.LabelKey = labelId;
        Control.Storage.Appointments.Add(apt);
    }
}