Your search did not match any results.
Drop Down Button

Drop Down Button

The DropDownButton is a button that opens a drop-down menu. The button displays a text and an icon.

Menu items can be specified in the items or dataSource options. Use dataSource if data is remote or should be processed. To customize menu items, implement an itemTemplate.

The DropDownButton stores the most recent selected menu item if you set the useSelectMode option to true. In this case, the button uses the selected item’s text and icon.

You can implement a dropDownContentTemplate to replace the drop-down menu with custom content.

To track and handle events, use the onButtonClick, onItemClick, and onSelectionChanged event handlers.

@model DevExtreme.MVC.Demos.ViewModels.DropDownButtonViewModel <div class="dx-fieldset"> <div class="dx-fieldset-header">Single usage</div> <div class="dx-field"> <div class="dx-field-label"> Custom static text </div> <div class="dx-field-value"> @(Html.DevExtreme().DropDownButton() .Text("Download Trial") .Icon("save") .Width(173) .DropDownOptions(options => options.Width(230)) .DataSource(Model.Downloads) .OnItemClick("downloadButton_click") ) </div> </div> <div class="dx-field"> <div class="dx-field-label"> Custom main button action </div> <div class="dx-field-value"> @(Html.DevExtreme().DropDownButton() .SplitButton(true) .Text("Sandra Johnson") .Width(173) .Icon("../../Content/Images/gym/coach-woman.png") .DisplayExpr("Text") .KeyExpr("Value") .UseSelectMode(false) .DataSource(Model.ProfileSettings) .OnButtonClick("profileButton_click") .OnItemClick("profileItem_click") ) </div> </div> </div> <div class="dx-fieldset"> <div class="dx-fieldset-header">Usage in a toolbar</div> <div class="dx-field"> @(Html.DevExtreme().Toolbar() .Items(items => { items.Add() .Widget(w => w.DropDownButton() .DataSource(Model.Alignments) .DisplayExpr("Text") .KeyExpr("Value") .SelectedItemKey("left") .Width(120) .StylingMode(ButtonStylingMode.Text) .UseSelectMode(true) .OnSelectionChanged("change_alignment") ) .Location(ToolbarItemLocation.Before); items.Add() .Widget(w => w.DropDownButton() .DataSource(Model.Colors) .StylingMode(ButtonStylingMode.Text) .Icon("square") .OnInitialized("init_colorpicker") .DropDownContentTemplate(new TemplateName("colorpicker-template")) ) .Location(ToolbarItemLocation.Before); items.Add() .Widget(w => w.DropDownButton() .DisplayExpr("Text") .KeyExpr("Value") .SelectedItemKey("14") .StylingMode(ButtonStylingMode.Text) .UseSelectMode(true) .DataSource(Model.FontSizes) .OnSelectionChanged("change_size") .ItemTemplate(@<text> <div style="font-size: <%- Text %>;"><%- Text %></div> </text>) ) .Location(ToolbarItemLocation.Before); items.Add() .Widget(w => w.DropDownButton() .DisplayExpr("Text") .KeyExpr("Value") .SelectedItemKey("1.35") .StylingMode(ButtonStylingMode.Text) .UseSelectMode(true) .DataSource(Model.LineHeights) .Icon("indent") .OnSelectionChanged("change_lineHeight") ) .Location(ToolbarItemLocation.Before); }) ) </div> <div class="dx-field"> <p id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div> </div> @using (Html.DevExtreme().NamedTemplate("colorpicker-template")) { <div class="custom-color-picker"> @foreach (var color in Model.Colors) {<i style="color: @color" class="color dx-icon dx-icon-square" onclick="onColorClick('@color')"></i>} </div> } <script> function downloadButton_click(e) { DevExpress.ui.notify("Download " + e.itemData, "success", 600); } function profileButton_click(e) { DevExpress.ui.notify("Go to " + e.component.option("text") + "'s profile", "success", 600); } function profileItem_click(e) { DevExpress.ui.notify(e.itemData.Text, "success", 600); } function change_alignment(e) { $("#text").css("text-align", e.item.Value); } function change_size(e) { $("#text").css("font-size", e.item.Text); } function change_lineHeight(e) { $("#text").css("line-height", e.item.Value); } var dropDownButton; function init_colorpicker(e) { dropDownButton = e.component; } function onColorClick(color) { var $colorIcon = dropDownButton.$element().find(".dx-dropdownbutton-action .dx-icon").first(); applyColor($("#text"), color); applyColor($colorIcon, color); dropDownButton.close(); } function applyColor($element, color) { if (color) { $element.removeClass("dx-theme-text-color"); $element.css("color", color); } else { $element.addClass("dx-theme-text-color"); } } </script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace DevExtreme.MVC.Demos.Models { public class ExtendedListItemData { public string Value { get; set; } public string Text { get; set; } public string icon { get; set; } public string badge { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace DevExtreme.MVC.Demos.Models { public class SimpleData { public string Value { get; set; } public string Text { get; set; } } }
.demo-container .dx-fieldset:first-child { width: 500px; } .custom-color-picker { width: 82px; padding: 5px; } .dx-button-content img.dx-icon { width: 24px; height: 24px; } .color { cursor: pointer; font-size: 18px; } #text { line-height: 1.35; }