Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
@model DevExtreme.NETCore.Demos.ViewModels.DropDownButtonViewModel
<div class="dx-fieldset">
<div class="dx-fieldset-header">Standalone button</div>
<div class="dx-field">
<div class="dx-field-label">
Text and icon
</div>
<div class="dx-field-value">
@(Html.DevExtreme().DropDownButton()
.Text("Download Trial")
.Icon("save")
.DropDownOptions(options => options.Width(230))
.DataSource(Model.Downloads)
.OnItemClick("downloadButton_click")
)
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">
Custom template and actions
</div>
<div class="dx-field-value">
@(Html.DevExtreme().DropDownButton()
.ID("custom-template")
.SplitButton(true)
.DisplayExpr("Text")
.KeyExpr("Value")
.UseSelectMode(false)
.DataSource(Model.ProfileSettings)
.OnButtonClick("profileButton_click")
.OnItemClick("profileItem_click")
.Template(@<text>
<div class="button-img-container">
<div class="button-img-indicator"></div>
<img class="button-img" src="@Url.Content("~/images/employees/51.png")" alt="employee" />
</div>
<div class="text-container">
<div class="button-title">Olivia Peyton</div>
<div class="button-row">IT Manager</div>
</div>
</text>)
)
</div>
</div>
</div>
<div class="dx-fieldset">
<div class="dx-fieldset-header">Embedded 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("justify")
.Width(125)
.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")
.DropDownOptions(o => o.Width("auto"))
.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.element).find('.button-title').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.css("color", color);
} else {
$element.css("color", "");
}
}
</script>
using DevExtreme.AspNet.Data;
using Microsoft.AspNetCore.Mvc;
using DevExtreme.NETCore.Demos.Models.SampleData;
using DevExtreme.NETCore.Demos.ViewModels;
using System.Linq;
namespace DevExtreme.NETCore.Demos.Controllers {
public class DropDownButtonController : Controller {
public ActionResult Overview() {
return View(new DropDownButtonViewModel() {
Colors = DropDownButtonData.Colors,
Alignments = DropDownButtonData.Alignments,
Downloads = DropDownButtonData.Downloads,
ProfileSettings = DropDownButtonData.ProfileSettings,
FontSizes = DropDownButtonData.FontSizes,
LineHeights = DropDownButtonData.LineHeights
});
}
}
}
using System.Collections.Generic;
namespace DevExtreme.NETCore.Demos.Models.SampleData {
public static class DropDownButtonData {
public static readonly IEnumerable<string> Colors = new[] { null, "#980000", "#ff0000", "#ff9900", "#ffff00", "#00ff00", "#00ffff", "#4a86e8", "#0000ff", "#9900ff", "#ff00ff", "#ff3466" };
public static readonly IEnumerable<string> Downloads = new[] { "Download Trial For Visual Studio", "Download Trial For All Platforms", "Package Managers" };
public static readonly IEnumerable<ExtendedListItemData> ProfileSettings = new[] {
new ExtendedListItemData{ Text = "Profile", Value = "1", icon = "user" },
new ExtendedListItemData{ Text = "Messages", Value = "2", icon = "email", badge = "5" },
new ExtendedListItemData{ Text = "Friends", Value = "3", icon = "group" },
new ExtendedListItemData{ Text = "Exit", Value = "4", icon = "runner" }
};
public static readonly IEnumerable<ExtendedListItemData> Alignments = new[] {
new ExtendedListItemData{ Text = "Left", Value = "left", icon = "alignleft" },
new ExtendedListItemData{ Text = "Right", Value = "right", icon = "alignright" },
new ExtendedListItemData{ Text = "Center", Value = "center", icon = "aligncenter" },
new ExtendedListItemData{ Text = "Justify", Value = "justify", icon = "alignjustify" }
};
public static readonly IEnumerable<SimpleData> FontSizes = new[] {
new SimpleData{ Text = "10px", Value = "10" },
new SimpleData{ Text = "12px", Value = "12" },
new SimpleData{ Text = "14px", Value = "14" },
new SimpleData{ Text = "16px", Value = "16" },
new SimpleData{ Text = "18px", Value = "18" }
};
public static readonly IEnumerable<SimpleData> LineHeights = new[] {
new SimpleData{ Text = "1", Value = "1" },
new SimpleData{ Text = "1.35", Value = "1.35" },
new SimpleData{ Text = "1.5", Value = "1.5" },
new SimpleData{ Text = "2", Value = "2" }
};
}
}
using DevExtreme.NETCore.Demos.Models;
using System.Collections.Generic;
namespace DevExtreme.NETCore.Demos.ViewModels {
public class DropDownButtonViewModel {
public IEnumerable<string> Downloads { get; set; }
public IEnumerable<string> Colors { get; set; }
public IEnumerable<ExtendedListItemData> Alignments { get; set; }
public IEnumerable<SimpleData> FontSizes { get; set; }
public IEnumerable<SimpleData> LineHeights { get; set; }
public IEnumerable<ExtendedListItemData> ProfileSettings { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace DevExtreme.NETCore.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.NETCore.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;
}
.text-container {
padding-inline-start: 12px;
padding-inline-end: 4px;
display: flex;
align-items: flex-start;
flex-direction: column;
}
.button-img-container {
position: relative;
height: 32px;
}
.button-img {
width: 32px;
height: 32px;
position: relative;
border-width: 1px;
border-style: solid;
border-color: var(--dx-color-border);
border-radius: 50%;
}
.button-img-indicator {
position: absolute;
background-color: var(--dx-color-danger);
top: -1px;
inset-inline-end: -1px;
width: 10px;
height: 10px;
border-radius: 50%;
border-width: 2px;
border-style: solid;
border-color: var(--dx-color-main-bg);
z-index: 1;
}
.button-title {
line-height: 20px;
}
.button-row {
font-size: 12px;
line-height: 14px;
opacity: 0.6;
}
#custom-template .dx-button {
height: 46px;
}
#custom-template .dx-button.dx-dropdownbutton-action .dx-button-content {
padding-inline-start: 12px;
padding-inline-end: 12px;
}
Menu items can be specified in the items or dataSource properties. Use dataSource if data is remote or should be processed.
DropDownButton stores the most recent selected menu item if you set the useSelectMode property to true
. In this case, the button uses the selected item's text and icon.
To customize DropDownButton, specify the the following options:
-
itemTemplate
Customizes menu items. -
template
Customizes a base button. -
dropDownContentTemplate
Replaces the drop-down menu with custom content.
To track and handle events, use the onButtonClick, onItemClick, and onSelectionChanged event handlers.