Ticket T445336
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

ASPxScheduler - The client-side Menu.Popup event stops firing after the menu items are hidden

How to show popup menu depending on LabelKey?

created 8 years ago

How to show different menu items depending of appointment LabelKey?

I have tried something like this…

C#
settings.Init = (s, e) => { MVCxScheduler scheduler = (MVCxScheduler)s; scheduler.PopupMenuShowing += (send, evargs) => { evargs.Menu.Items.Clear(); evargs.Menu.ClientSideEvents.ItemClick = "OnSchedulerMenuItemClick"; foreach (DevExpress.XtraScheduler.Internal.Implementations.AppointmentInstance abc in scheduler.Storage.Appointments.Items) { if (abc.LabelKey.ToString() == "1") { DevExpress.Web.MenuItem mi = new DevExpress.Web.MenuItem(); mi.Name = "ScheduledLabel"; mi.Text = "Scheduled"; evargs.Menu.Items.Add(mi); } else if (abc.LabelKey.ToString() == "2") { DevExpress.Web.MenuItem mi = new DevExpress.Web.MenuItem(); mi.Name = "CanceledLabel"; mi.Text = "Canceled"; evargs.Menu.Items.Add(mi); } } }; };

But with this doesn't work.

Would you tell me please what am I doing wrong?

Tnx.

Answers approved by DevExpress Support

created 8 years ago

Hello Goran,
I have attached a sample project to demonstrate how to implement this scenario. Allow me to briefly describe the key points of the demonstrated solution:

  1. In a server-side PopupMenuShowing event handler, I added two custom menu items and removed the "Labels" standard menu:
C#
settings.PopupMenuShowing = (sched, evargs) => { if(!evargs.Menu.MenuId.Equals(SchedulerMenuItemId.AppointmentMenu)) return; var itemScheduled = new DevExpress.Web.MenuItem("Scheduled", "Scheduled"); evargs.Menu.Items.Add(itemScheduled); var itemCanceled = new DevExpress.Web.MenuItem("Canceled", "Canceled"); evargs.Menu.Items.Add(itemCanceled); var labelsMenuItem = evargs.Menu.Items.FindByName("LabelSubMenu"); if(labelsMenuItem != null) labelsMenuItem.Visible = false; evargs.Menu.ClientSideEvents.PopUp = "OnAppointmentMenuPopup"; };
  1. I passed information about appointment labels from server-side to client-side in the InitClientAppointment event handler:
C#
settings.InitClientAppointment = (sched, evargs) => { evargs.Properties.Add(ClientSideAppointmentFieldNames.LabelId, evargs.Appointment.LabelKey); };
  1. In a client-side Menu.Popup event handler, I checked a selected appointment's label and changed visibility of the "Scheduled" and "Canceled" menu items:
JavaScript
function OnAppointmentMenuPopup(s, e) { var selectedAppointment = scheduler.GetAppointmentById(scheduler.GetSelectedAppointmentIds()[0]); var apptLabelId = selectedAppointment.GetLabelId(); for (var i = 0; i < e.item.items.length; i++) { var currentItem = e.item.items[i]; if (currentItem.name == "Scheduled") { currentItem.SetVisible(apptLabelId == "2"); } if (currentItem.name == "Canceled") { currentItem.SetVisible(apptLabelId == "1"); } } }
  1. When an end-user selected the "Scheduled" and "Canceled" menu items, I changed a label of a currently selected appointment:
JavaScript
function OnSchedulerMenuItemClick(s, e) { var selectedAppointment = scheduler.GetAppointmentById(scheduler.GetSelectedAppointmentIds()[0]); if (e.itemName == "Scheduled") { selectedAppointment.SetLabelId(1); scheduler.UpdateAppointment(selectedAppointment); } if (e.itemName == "Canceled") { selectedAppointment.SetLabelId(2); scheduler.UpdateAppointment(selectedAppointment); } }

I have also attached a video illustrating how this sample operates on my side.
I hope you will find this sample helpful.

    Show previous comments (4)
    GM GM
    Goran Milašinović 8 years ago

      This don't cover what I need to do.

      I have created my own list when right mouse button is clicked.

      Tnx anyway.

      DevExpress Support Team 8 years ago

        I see, Goran.
        We will try to fix this issue as soon as we can.
        You will be automatically notified when the status of the A client-side Menu.Popup event stops raising after hiding the menu items ticket is changed.

        DevExpress Support Team 8 years ago

          Hello Goran,
          I have found a workaround for your scenario. To avoid this issue, make all the context menu items visible in the client-side Menu.CloseUp event handler:

          C#
          settings.PopupMenuShowing = (send, evargs) => { evargs.Menu.Items.Clear(); if (evargs.Menu.MenuId == SchedulerMenuItemId.AppointmentMenu) { DevExpress.Web.MenuItem itemScheduled = new DevExpress.Web.MenuItem("SCHEDULED", "miSchedulerScheduled"); evargs.Menu.Items.Add(itemScheduled); DevExpress.Web.MenuItem itemCanceled = new DevExpress.Web.MenuItem("CANCELED", "miSchedulerCanceled"); evargs.Menu.Items.Add(itemCanceled); var labelsMenuItem = evargs.Menu.Items.FindByName("LabelSubMenu"); if (labelsMenuItem != null) labelsMenuItem.Visible = false; evargs.Menu.ClientSideEvents.PopUp = "OnAppointmentMenuPopup"; evargs.Menu.ClientSideEvents.CloseUp = "OnAppointmentMenuCloseUp"; } };
          JavaScript
          function OnAppointmentMenuCloseUp(s, e) { for (var i = 0; i < e.item.items.length; i++) e.item.items[i].SetVisible(true); }

          Please try this solution and let me know your results.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.