Your search did not match any results.

Button Group

ButtonGroup displays a set of two-state buttons and allows users to select one or multiple buttons. This demo illustrates how to configure the ButtonGroup in the following steps:

  • Bind ButtonGroup to data.

  • Enable or disable multiple selection.

  • Customize the ButtonGroup appearance.

Backend API
<div class="buttongroups-container"> @(Html.DevExtreme().ButtonGroup() .KeyExpr("alignment") .StylingMode(ButtonStylingMode.Outlined) .Items(items => { items.Add().Icon("alignleft").Hint("Align left").Option("alignment", "left"); items.Add().Icon("aligncenter").Hint("Center").Option("alignment", "center"); items.Add().Icon("alignright").Hint("Align right").Option("alignment", "right"); items.Add().Icon("alignjustify").Hint("Justify").Option("alignment", "justify"); }) .SelectedItemKeys(new[] { "left" }) .OnItemClick("buttonGroup_ItemClick") ) @(Html.DevExtreme().ButtonGroup() .KeyExpr("style") .StylingMode(ButtonStylingMode.Outlined) .SelectionMode(ButtonGroupSelectionMode.Multiple) .Items(items => { items.Add().Icon("bold").Hint("Bold").Option("style", "bold"); items.Add().Icon("italic").Hint("Italic").Option("style", "italic"); items.Add().Icon("underline").Hint("Underlined").Option("style", "underline"); items.Add().Icon("strike").Hint("Strikethrough").Option("style", "strike"); }) .OnItemClick("buttonGroup_ItemClick") ) </div> <div class="buttongroups-container"> @(Html.DevExtreme().ButtonGroup() .KeyExpr("alignment") .StylingMode(ButtonStylingMode.Text) .Items(items => { items.Add().Icon("alignleft").Hint("Align left").Option("alignment", "left"); items.Add().Icon("aligncenter").Hint("Center").Option("alignment", "center"); items.Add().Icon("alignright").Hint("Align right").Option("alignment", "right"); items.Add().Icon("alignjustify").Hint("Justify").Option("alignment", "justify"); }) .SelectedItemKeys(new[] { "left" }) .OnItemClick("buttonGroup_ItemClick") ) <div class="multiple-selection-styling-mode"> @(Html.DevExtreme().ButtonGroup() .KeyExpr("style") .StylingMode(ButtonStylingMode.Text) .SelectionMode(ButtonGroupSelectionMode.Multiple) .Items(items => { items.Add().Icon("bold").Hint("Bold").Option("style", "bold"); items.Add().Icon("italic").Hint("Italic").Option("style", "italic"); items.Add().Icon("underline").Hint("Underlined").Option("style", "underline"); items.Add().Icon("strike").Hint("Strikethrough").Option("style", "strike"); }) .OnItemClick("buttonGroup_ItemClick") ) </div> </div> <script> function buttonGroup_ItemClick(e) { DevExpress.ui.notify({ message: 'The "' + e.itemData.hint + '" button was clicked', width: 320 }, "success", 1000); } </script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class ButtonGroupController : Controller { public ActionResult Overview() { return View(); } } }
.buttongroups-container { display: flex; justify-content: center; font-size: 16px; } .buttongroups-container > div { padding: 0 12px; } .buttongroups-container:first-child { margin-top: 120px; margin-bottom: 40px; } .multiple-selection-styling-mode { border-left-width: 1px; border-left-style: solid; border-color: #dddddd; }

Bind ButtonGroup to Data

Use the items array to populate ButtonGroup with data. You can specify the following fields in data objects:

Process Button Selection

Set the keyExpr property to the data field that supplies keys used to distinguish the selected buttons. In this demo, the selectedItemKeys property contains the keys of the selected buttons. This property allows you to predefine selected buttons. To enable multiple selection, set the selectionMode property to multiple.

Use the onItemClick function to process clicks on buttons.

Customize the Buttongroup Appearance

Specify the stylingMode property and select one of the three predefined styles. In this demo, the button groups in the first row have the outlined style, while others have the text style. You can specify the buttonTemplate property to customize the apperance of each button.

To get started with the DevExtreme ButtonGroup component, refer to the following tutorial for step-by-step instructions: Getting Started with ButtonGroup.