| layout | post |
|---|---|
| title | Context-Menu |
| description | context menu |
| platform | js |
| control | Menu |
| documentation | ug |
| api | /api/js/ejmenu |
A context menu is a type of menu in a graphical user interface (GUI) that appears when you perform right click operation. For this operation, you have to disable the openOnClick property. In this Menu control you can use a context menu by specifying the type of menu as ContextMenu using menuType. A context also provides support for nested level of menu items.
Before you use the context menu, provide the target area for it and mention that area id in the property named as contextMenuTarget.
In the following example, a context menu for the division containing text is created. In this, when you perform right click operation, the following menu appears with open, edit, etc.
Add the following code in your HTML page.
{% highlight html %}
{% endhighlight %}
{% highlight javascript %}
// Add the following code in your script section.
jQuery(function ($) {
$("#contextMenu").ejMenu({
menuType: ej.MenuType.ContextMenu,
openOnClick: false,
contextMenuTarget: "#target"
});
});
{% endhighlight %}
Add the following code in your style section.
{% highlight css %}
<style type="text/css"> .textarea { border: 1px solid; padding: 10px; position: relative; text-align: justify; width: 463px; color: gray; margin: 0 auto; } </style>{% endhighlight %}
The following screen shot displays the output of the above code.
You can hide and show the context menu using the following methods.
Hides the context menu control using hide method. Add the following script code in the sample in order to hide the context menu.
{% highlight javascript %}
jQuery(function ($) {
$("#contextMenu").ejMenu({
menuType: ej.MenuType.ContextMenu,
openOnClick: false,
contextMenuTarget: "#target"
});
//initialize the menu object
var menuObj = $("#contextMenu ").data("ejMenu");
//To hide the context menu
menuObj.hide();
});
{% endhighlight %}
Shows the context menu control using show method. Add the following script code in the sample in order to show the context menu.
{% highlight javascript %}
jQuery(function ($) {
$("#contextMenu").ejMenu({
menuType: ej.MenuType.ContextMenu,
openOnClick: false,
contextMenuTarget: "#target"
});
//initialize the menu object
var menuObj = $("#contextMenu ").data("ejMenu");
//To show the context menu
menuObj.show();
});
{% endhighlight %}
