Context Menus
You can use the Menu control to create context menus.
For example, this fiddle creates a single context menu and handles the 'contextmenu' event on several elements to show the menu when the user requests it:
I have a Context Menu.
I have the same Context Menu.
You guessed it, me too.
The same approach works with all Wijmo controls:
FlexChart with ContextMenu
FlexGrid with ContextMenu
Country
Sales
Expenses
Downloads
US
7,262
4,086
15,360
Germany
5,581
1,030
11,177
UK
9,060
2,210
19,550
Japan
2,737
1,459
9,346
Italy
6,326
2,347
19,643
Greece
303
4,311
19,906
Country
Sales
Expenses
Downloads
0
- C1Input/MenusContextMenus.js
- C1Input/MenusContextMenus.css
- MenusContextMenusController.cs
- MenusContextMenus.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // This file locates: "Scripts/Lesson/C1Input/MenusContextMenus.js". c1.documentReady(function () { var menu = wijmo.Control.getControl( '#ctxMenu' ); menu.itemClicked.addHandler(function (s, e) { alert( 'Executing **' + menu.selectedValue + '** for element **' + menu.owner.id + '**' ); }); // use it as a context menu for one or more elements var els = document.querySelectorAll( '.has-ctx-menu' ); for (var i = 0; i < els.length; i++) { els[i].addEventListener( 'contextmenu' , function (e) { menu.owner = wijmo.closest(e.target, '.has-ctx-menu' ); if (menu.owner) { e.preventDefault(); menu.show(e); } }, true ); } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | // This file locates: "Content/css/Lesson/C1Input/MenusContextMenus.css". .owners:after { content: "" ; clear: both; display: block; } .owners > div { float : left; margin: 20px; padding: 20px; } .wj-flexgrid { max-height: 250px; } .wj-flexchart { max-height: 250px; } .ctx-menu { padding: 3px; min-width: 120px; background: #FFFBDD; } .ctx-menu .wj-listbox-item { text-align: center; margin: 6px; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1InputController : Controller { // GET: MenusContextMenus public ActionResult MenusContextMenus() { return View(Models.FlexChartData.GetSales1()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | @model IEnumerable< FlexChartData.Sale > < h1 > @Html .Raw(Resources.C1Input.MenusContextMenus_Title) </ h1 > < p > @Html .Raw(Resources.C1Input.MenusContextMenus_Text1) </ p > < p > @Html .Raw(Resources.C1Input.MenusContextMenus_Text2) </ p > < div class = "owners" > < div id = "FIRST" class = "has-ctx-menu" style = "background:#f0a0a0" > @Html .Raw(Resources.C1Input.MenusContextMenus_Text3) </ div > < div id = "SECOND" class = "has-ctx-menu" style = "background:#a0f0a0" > @Html .Raw(Resources.C1Input.MenusContextMenus_Text4) </ div > < div id = "THIRD" class = "has-ctx-menu" style = "background:#a0a0f0" > @Html .Raw(Resources.C1Input.MenusContextMenus_Text5) </ div > </ div > < p > @Html .Raw(Resources.C1Input.MenusContextMenus_Text6) </ p > < h3 > @Html .Raw(Resources.C1Input.MenusContextMenus_Title1) </ h3 > @ (Html.C1().FlexChart< FlexChartData.Sale >().Id( "theChart" ) .CssClass( "has-ctx-menu" ) .Bind( "Country" , Model) .Series(sb => { sb.Add().Binding( "Sales" ).Name( "Sales" ); sb.Add().Binding( "Expenses" ).Name( "Expenses" ); }) ) < div id = "" class = "" ></ div > < h3 > @Html .Raw(Resources.C1Input.MenusContextMenus_Title2) </ h3 > @ (Html.C1().FlexGrid< FlexChartData.Sale >().Id( "theGrid" ) .CssClass( "has-ctx-menu" ) .Bind(Model) ) @ (Html.C1().Menu().Id( "ctxMenu" ) .DropDownCssClass( "ctx-menu" ) .SelectedValuePath( "CommandParameter" ) .MenuItems(items=> { items.Add().Header( "<span class=\"glyphicon glyphicon-asterisk\"></span> " + Resources.C1Input.MenusContextMenus_Text7).CommandParameter( "NEW" ); items.Add().Header( "<span class=\"glyphicon glyphicon-folder-open\"></span> " + Resources.C1Input.MenusContextMenus_Text8).CommandParameter( "OPEN" ); items.Add().Header( "<span class=\"glyphicon glyphicon-floppy-disk\"></span> " + Resources.C1Input.MenusContextMenus_Text9).CommandParameter( "SAVE" ); items.AddSeparator(); items.Add().Header( "<span class=\"glyphicon glyphicon-remove\"></span> " + Resources.C1Input.MenusContextMenus_Text10).CommandParameter( "EXIT" ); }) .CssStyle( "display" , "none" ) ) |