Menu

The Menu control extends the ComboBox to add features like a non-editable header, an itemClicked event, and commands. Use the selectedItem property to determine what action to take when items is clicked.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as input from '@grapecity/wijmo.input'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create file and edit menus let menuFile = createMenu('menuFile'); menuFile.itemClicked.addHandler(menuClick); // let menuEdit = createMenu('menuEdit'); menuEdit.itemClicked.addHandler(menuClick); // // use the same event handler for both function menuClick(sender) { alert(`You selected option **${sender.selectedIndex}** from menu **${sender.header}**`); } // // create menu from markup function createMenu(elementId) { // get host element, header, items let host = document.getElementById(elementId), header = host.firstChild.textContent.trim(), items = host.querySelectorAll('div'), menuItems = []; // for (let i = 0; i < items.length; i++) { let item = items[i]; menuItems.push(item.outerHTML); } // // clear host and instantiate menu host.innerHTML = ''; let menu = new input.Menu(host, { header: header, itemsSource: menuItems }); // // done, return menu return menu; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Menu</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="menuFile"> File <div> <span class="glyphicon glyphicon-asterisk"></span>&nbsp;&nbsp; <b>New</b> <br> <small><i>create a new file</i></small></div> <div> <span class="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp; <b>Open</b> <br> <small><i>open an existing file or folder</i></small></div> <div> <span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp; <b>Save</b> <br> <small><i>save the current file</i></small></div> <div class="wj-separator"></div> <div> <span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp; <b>Exit</b> <br> <small><i>exit the application</i></small></div> </div> <div id="menuEdit"> Edit <div> <span class="glyphicon glyphicon-scissors"></span>&nbsp;&nbsp; <b>Cut</b> <br> <small><i>move the current selection to the clipboard</i></small> </div> <div> <span class="glyphicon glyphicon-copy"></span>&nbsp;&nbsp; <b>Copy</b> <br> <small><i>copy the current selection to the clipboard</i></small> </div> <div> <span class="glyphicon glyphicon-paste"></span>&nbsp;&nbsp; <b>Paste</b> <br> <small><i>insert clipboard content at the cursor position</i></small> </div> </div> </div> </body> </html> .wj-dropdown { margin-right: 5px; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as input from '@grapecity/wijmo.input'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { menuItemClicked(menu: input.Menu) { alert(`You selected option **${menu.selectedIndex}** from menu **${menu.header}**`); } } // @NgModule({ imports: [WjInputModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Menu</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-menu #fileMenu [header]="'File'" (itemClicked)="menuItemClicked(fileMenu)"> <wj-menu-item> <span class="glyphicon glyphicon-asterisk"></span>&nbsp;&nbsp; <b>New</b> <br> <small><i>create a new file</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp; <b>Open</b> <br> <small><i>open an existing file or folder</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp; <b>Save</b> <br> <small><i>save the current file</i></small> </wj-menu-item> <wj-menu-separator></wj-menu-separator> <wj-menu-item> <span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp; <b>Exit</b> <br> <small><i>exit the application</i></small> </wj-menu-item> </wj-menu> <wj-menu #editMenu [header]="'Edit'" (itemClicked)="menuItemClicked(editMenu)"> <wj-menu-item> <span class="glyphicon glyphicon-scissors"></span>&nbsp;&nbsp; <b>Cut</b> <br> <small><i>move the current selection to the clipboard</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-copy"></span>&nbsp;&nbsp; <b>Copy</b> <br> <small><i>copy the current selection to the clipboard</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-paste"></span>&nbsp;&nbsp; <b>Paste</b> <br> <small><i>insert clipboard content at the cursor position</i></small> </wj-menu-item> </wj-menu> </div> .wj-dropdown { margin-right: 5px; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <wj-menu :header="'File'" :itemClicked="menuItemClicked"> <wj-menu-item> <span class="glyphicon glyphicon-asterisk"></span>&nbsp;&nbsp; <b>New</b> <br> <small><i>create a new file</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp; <b>Open</b> <br> <small><i>open an existing file or folder</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp; <b>Save</b> <br> <small><i>save the current file</i></small> </wj-menu-item> <wj-menu-separator></wj-menu-separator> <wj-menu-item> <span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp; <b>Exit</b> <br> <small><i>exit the application</i></small> </wj-menu-item> </wj-menu> <wj-menu :header="'Edit'" :itemClicked="menuItemClicked"> <wj-menu-item> <span class="glyphicon glyphicon-scissors"></span>&nbsp;&nbsp; <b>Cut</b> <br> <small><i>move the current selection to the clipboard</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-copy"></span>&nbsp;&nbsp; <b>Copy</b> <br> <small><i>copy the current selection to the clipboard</i></small> </wj-menu-item> <wj-menu-item> <span class="glyphicon glyphicon-paste"></span>&nbsp;&nbsp; <b>Paste</b> <br> <small><i>insert clipboard content at the cursor position</i></small> </wj-menu-item> </wj-menu> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; let App = Vue.extend({ name: 'app', data:function() { return { } }, methods: { menuItemClicked: function(menu) { alert(`You selected option **${menu.selectedIndex}** from menu **${menu.header}**`); } } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .container-fluid .wj-dropdown { margin-right: 5px; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Menu</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjInput from '@grapecity/wijmo.react.input'; // class App extends React.Component { constructor(props) { super(props); this.menuItemClicked = (menu) => { alert(`You selected option **${menu.selectedIndex}** from menu **${menu.header}**`); }; } render() { return <div className="container-fluid"> <wjInput.Menu header="File" itemClicked={this.menuItemClicked}> <wjInput.MenuItem> <span className="glyphicon glyphicon-asterisk"></span>&nbsp;&nbsp; <b>New</b> <br /> <small><i>create a new file</i></small> </wjInput.MenuItem> <wjInput.MenuItem> <span className="glyphicon glyphicon-folder-open"></span>&nbsp;&nbsp; <b>Open</b> <br /> <small><i>open an existing file or folder</i></small> </wjInput.MenuItem> <wjInput.MenuItem> <span className="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp; <b>Save</b> <br /> <small><i>save the current file</i></small> </wjInput.MenuItem> <wjInput.MenuSeparator></wjInput.MenuSeparator> <wjInput.MenuItem> <span className="glyphicon glyphicon-remove"></span>&nbsp;&nbsp; <b>Exit</b> <br /> <small><i>exit the application</i></small> </wjInput.MenuItem> </wjInput.Menu> <wjInput.Menu header="Edit" itemClicked={this.menuItemClicked}> <wjInput.MenuItem> <span className="glyphicon glyphicon-scissors"></span>&nbsp;&nbsp; <b>Cut</b> <br /> <small><i>move the current selection to the clipboard</i></small> </wjInput.MenuItem> <wjInput.MenuItem> <span className="glyphicon glyphicon-copy"></span>&nbsp;&nbsp; <b>Copy</b> <br /> <small><i>copy the current selection to the clipboard</i></small> </wjInput.MenuItem> <wjInput.MenuItem> <span className="glyphicon glyphicon-paste"></span>&nbsp;&nbsp; <b>Paste</b> <br /> <small><i>insert clipboard content at the cursor position</i></small> </wjInput.MenuItem> </wjInput.Menu> </div>; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-dropdown { margin-right: 5px; } body { margin-bottom: 24pt; }