Your search did not match any results.
Menu

Menu

Documentation

The Menu component is a panel with clickable items. A click on an item opens a drop-down menu, which can contain several submenus.

Backend API
Copy to CodePen
Apply
Reset
window.onload = function () { const showSubmenuModes = [{ name: 'onHover', delay: { show: 0, hide: 500 }, }, { name: 'onClick', delay: { show: 0, hide: 300 }, }]; const showFirstSubmenuMode = ko.observable(showSubmenuModes[1]); const orientation = ko.observable('horizontal'); const closeOnMouseLeave = ko.observable(false); const productName = ko.observable(''); const productPrice = ko.observable(''); const productImage = ko.observable(''); const viewModel = { menuOptions: { dataSource: menuData, displayExpr: 'name', onItemClick(data) { const item = data.itemData; if (item.price) { productImage(item.icon); productName(item.name); productPrice(`$${item.price}`); } }, hideSubmenuOnMouseLeave: closeOnMouseLeave, showFirstSubmenuMode, orientation, }, submenuModeOptions: { items: showSubmenuModes, value: showFirstSubmenuMode, displayExpr: 'name', }, orientationOptions: { items: ['horizontal', 'vertical'], value: orientation, }, mouseLeaveOptions: { value: closeOnMouseLeave, text: 'Hide Submenu on Mouse Leave', }, productName, productPrice, productImage, }; ko.applyBindings(viewModel, document.getElementById('menu')); };
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.light.css" /> <script src="https://cdn3.devexpress.com/jslib/21.2.3/js/dx.all.js"></script> <script src="data.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="form" id="menu"> <div> <div class="label">Catalog:</div> <div data-bind="dxMenu: menuOptions"></div> <!-- ko if: productPrice() --> <div id="product-details"> <img src="" data-bind="attr: { src: productImage }" /> <div class="name" data-bind="text: productName"></div> <div class="price" data-bind="text: productPrice"></div> </div> <!-- /ko --> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <div>Show First Submenu Mode</div> <div data-bind="dxSelectBox: submenuModeOptions"></div> </div> <div class="option"> <div>Orientation</div> <div data-bind="dxSelectBox: orientationOptions"></div> </div> <div class="option"> <div data-bind="dxCheckBox: mouseLeaveOptions"></div> </div> </div> </div> </div> </body> </html>
.form { margin-left: 3px; } .form > div:first-child { margin-right: 320px; } .label { font-size: 22px; } #product-details { width: 400px; height: 400px; margin: 20px auto 0; } #product-details > img { height: 300px; width: 400px; } #product-details > .name { text-align: center; font-size: 20px; } #product-details > .price { text-align: center; font-size: 24px; } .dark #product-details > div { color: #f0f0f0; } .options { padding: 20px; position: absolute; bottom: 0; right: 0; width: 260px; top: 0; background-color: rgba(191, 191, 191, 0.15); } .caption { font-size: 18px; font-weight: 500; } .option { margin-top: 10px; } .hidden { visibility: hidden; }
const menuData = [{ id: '1', name: 'Video Players', items: [{ id: '1_1', name: 'HD Video Player', price: 220, icon: '../../../../images/products/1.png', }, { id: '1_2', name: 'SuperHD Video Player', icon: '../../../../images/products/2.png', price: 270, }], }, { id: '2', name: 'Televisions', items: [{ id: '2_1', name: 'SuperLCD 42', icon: '../../../../images/products/7.png', price: 1200, }, { id: '2_2', name: 'SuperLED 42', icon: '../../../../images/products/5.png', price: 1450, }, { id: '2_3', name: 'SuperLED 50', icon: '../../../../images/products/4.png', price: 1600, }, { id: '2_4', name: 'SuperLCD 55 (Not available)', icon: '../../../../images/products/6.png', price: 1350, disabled: true, }, { id: '2_5', name: 'SuperLCD 70', icon: '../../../../images/products/9.png', price: 4000, }], }, { id: '3', name: 'Monitors', items: [{ id: '3_1', name: '19"', items: [{ id: '3_1_1', name: 'DesktopLCD 19', icon: '../../../../images/products/10.png', price: 160, }], }, { id: '3_2', name: '21"', items: [{ id: '3_2_1', name: 'DesktopLCD 21', icon: '../../../../images/products/12.png', price: 170, }, { id: '3_2_2', name: 'DesktopLED 21', icon: '../../../../images/products/13.png', price: 175, }], }], }, { id: '4', name: 'Projectors', items: [{ id: '4_1', name: 'Projector Plus', icon: '../../../../images/products/14.png', price: 550, }, { id: '4_2', name: 'Projector PlusHD', icon: '../../../../images/products/15.png', price: 750, }], }];