Back to Devexpress

ASPxClientGantt.ContextMenu Event

aspnet-js-aspxclientgantt-54861005.md

latest3.4 KB
Original Source

ASPxClientGantt.ContextMenu Event

Occurs when a user right-clicks a task or dependency to open the context menu.

Declaration

ts
ContextMenu: ASPxClientEvent<ASPxClientGanttContextMenuEventHandler<ASPxClientGantt>>

Event Data

The ContextMenu event's data class is ASPxClientGanttContextMenuEventArgs. The following properties provide information specific to this event:

PropertyDescription
cancelSpecifies whether to cancel the related action (for example, row edit, export). Inherited from ASPxClientCancelEventArgs.
htmlEventGets the DHTML event object that contains information about the processed event.
objectInfoGets information about the right-clicked object.

Remarks

The ContextMenu event enables you to create a custom context menu.

Follow the steps below to create a custom context menu:

  • Handle the ContextMenu event.

  • Set the e.cancel argument of the ContextMenuCustomization event to true to prevent the built-in context menu from showing.

To customize items of the built-in context menu, use the ContextMenuCustomization event.

Run Demo: ASPxGantt - Context Menu Run Demo: MVCxGantt - Context Menu

Example

The example below illustrates how to show the pop-up menu when a user right-clicks the control.

Web Forms:

aspx
<dx:ASPxGantt ID="Gantt" ClientInstanceName="clientGantt" >
    <ClientSideEvents 
        ContextMenu="function(s, e) { menu.ShowAtPos(e.htmlEvent.x,e.htmlEvent.y); }" 
        ContextMenuCustomization="function(s, e) { e.cancel = true; }"
    />
</dx:ASPxGantt>

<dx:ASPxPopupMenu runat="server" ID="popup" ClientInstanceName="menu">
    <Items>
        <dx:MenuItem Text="Item1" />
        <dx:MenuItem Text="Item2" />
    </Items>        
</dx:ASPxPopupMenu>

MVC:

cshtml
@Html.DevExpress().Gantt(settings => {
    settings.Name = "gantt";
    settings.ClientSideEvents.ContextMenuCustomization = "function (s, e) { e.cancel = true; }";
    settings.ClientSideEvents.ContextMenu = "function (s, e) { popup.ShowAtPos(e.htmlEvent.x,e.htmlEvent.y); }";
    ...
}).Bind(
    GanttDataProvider.Tasks, GanttDataProvider.Dependencies, 
    GanttDataProvider.Resources, GanttDataProvider.ResourceAssignments
).GetHtml()

@Html.DevExpress().PopupMenu(
    settings.Name = "popup";
    settings.Items.Add(item => {
        item.Text = "Item 1";
        item.Name = "Item 2";
    });
).GetHtml()

See Also

ASPxGantt - Overview

MVCxGantt - Overview

ASPxGantt - 'How To' Examples

MVCxGantt - 'How To' Examples

ASPxClientGantt Class

ASPxClientGantt Members