UI Widgets ContextMenu

A context menu widget.

Included in: dx.webappjs.js, dx.all.js

The dxContextMenu widget displays a single-level or multi-level context menu that performs an action when an item is clicked.

You can create a widget using one of the following approaches.

  • jQuery
    Use the dxContextMenu jQuery plug-in.

    HTML
    <div id="targetElement"></div>
    <div id="contextMenu"></div>
    JavaScript
    var menuItems = [
        { text: "Hide" },
        { text: "Delete" },
        {
            text: "Clipboard",
            items: [
                { text: "Copy text" },
                { text: "Clear text" },
                { text: "Paste text" }
            ]
        }
    ];
    $("#contextMenu").dxContextMenu({
        items: menuItems,
        target: '#targetElement'
    });
  • Knockout
    Add a div element and apply the dxContextMenu binding to this element.

    HTML
    <div id="targetElement"></div>
    <div data-bind="dxContextMenu: {
        items: menuItems,
        target: '#targetElement'
    }"></div>
  • Angular
    Add a div element and apply the dx-context-menu directive to this element.

    HTML
    <div id="targetElement"></div>
    <div dx-context-menu="{
        items: menuItems,
        target: '#targetElement'
    }"></div>

Note that DevExtreme widgets require you to link the jQuery and Globalize libraries to your application. If you use the Knockout or Angular approach, the Knockout or Angular library is also required.

See Also

You can find detailed information on the principles of working with the widget in the dxContextMenu section of the Menu Widgets article.

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div style="height:300px; max-width:750px; margin: 0 auto" ng-controller="demoController">
    <div id="targetElement">
        Make a right click
    </div>
    <div dx-context-menu="{
        items: menuItems,
        onItemClick: itemClicked,
        target: '#targetElement',
        bindingOptions: {
            visible: 'contextMenuVisible',
        }
    }"></div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.contextMenuVisible = false,
    $scope.menuItems = [
        { text: "Hide" },
        { text: "Delete" },
        {
            text: "Clipboard",
            items: [
                { text: "Copy text" },
                { text: "Clear text" },
                { text: "Paste text" }
            ]
        }
    ],
    $scope.showContextMenu = function(){
        $scope.contextMenuVisible = true;
    }
    $scope.itemClicked = function (data) {
        DevExpress.ui.notify("The \"" + data.itemData.text + "\" item is clicked", "success", 1500);
    }
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body{
    text-align: center;
}
#targetElement {
    margin-top: 40px;
    padding-top: 40px;
    display: inline-block;
    width: 80%;
    height: 170px;
    border-style: solid;
    background-color: lightgreen;
}
<div style="height:300px; max-width:750px; margin: 0 auto">
    <div id="targetElement">
        Make a right click
    </div>
    <div data-bind="dxContextMenu: {
        items: menuItems,
        visible: contextMenuVisible,
        onItemClick: itemClicked,
        target: '#targetElement'
    }"></div>
</div>
var myViewModel = {
    contextMenuVisible: ko.observable(false),
    menuItems: [
        { text: "Hide" },
        { text: "Delete" },
        {
            text: "Clipboard",
            items: [
                { text: "Copy text" },
                { text: "Clear text" },
                { text: "Paste text" }
            ]
        }
    ],
    itemClicked: function (data) {
        DevExpress.ui.notify("The \"" + data.itemData.text + "\" item is clicked", "success", 1500);
    }
};
ko.applyBindings(myViewModel);
body{
    text-align: center;
}
#targetElement {
    margin-top: 40px;
    padding-top: 40px;
    display: inline-block;
    width: 80%;
    height: 170px;
    border-style: solid;
    background-color: lightgreen;
}
<div style="height:300px; max-width:750px; margin: 0 auto">
    <div id="targetElement">Make a right click</div>
    <div id="myContextMenu"></div>
</div>
$("#myContextMenu").dxContextMenu({
    items: [
        { text: "Hide" },
        { text: "Delete" },
        {
            text: "Clipboard",
            items: [
                { text: "Copy text" },
                { text: "Clear text" },
                { text: "Paste text" }
            ]
        }
    ],
    onItemClick: function (data) {
        DevExpress.ui.notify("The \"" + data.itemData.text + "\" item is clicked", "success", 1500);
    },
    target: '#targetElement'
});
body{
    text-align: center;
}
#targetElement {
    margin-top: 40px;
    padding-top: 40px;
    display: inline-block;
    width: 80%;
    height: 170px;
    border-style: solid;
    background-color: lightgreen;
}

Configuration

An object defining configuration options for the dxContextMenu widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events exposed by this widget.

Default Item Template

This section lists the data source fields that are used in a default template for context menu items.

By default, a predefined item template is applied to display the items of this widget. This template is based on certain fields of the data source provided for this widget. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom item template based on these or other fields of your data source.

See Also