Your search did not match any results.
Button Group

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.

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.

Backend API
Copy to CodePen
Apply
Reset
$(() => { $('#single-selection').dxButtonGroup({ items: alignments, keyExpr: 'alignment', stylingMode: 'outlined', selectedItemKeys: ['left'], onItemClick(e) { DevExpress.ui.notify({ message: `The "${e.itemData.hint}" button was clicked`, width: 320 }, 'success', 1000); }, }); $('#multiple-selection').dxButtonGroup({ items: fontStyles, keyExpr: 'style', stylingMode: 'outlined', selectionMode: 'multiple', onItemClick(e) { DevExpress.ui.notify({ message: `The "${e.itemData.hint}" button was clicked`, width: 320 }, 'success', 1000); }, }); $('#single-selection-styling-mode').dxButtonGroup({ items: alignments, keyExpr: 'alignment', stylingMode: 'text', selectedItemKeys: ['left'], onItemClick(e) { DevExpress.ui.notify({ message: `The "${e.itemData.hint}" button was clicked`, width: 320 }, 'success', 1000); }, }); $('#multiple-selection-styling-mode').dxButtonGroup({ items: fontStyles, keyExpr: 'style', stylingMode: 'text', selectionMode: 'multiple', onItemClick(e) { DevExpress.ui.notify({ message: `The "${e.itemData.hint}" button was clicked`, width: 320 }, 'success', 1000); }, }); });
<!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> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/22.1.4/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/22.1.4/css/dx.light.css" /> <script src="https://cdn3.devexpress.com/jslib/22.1.4/js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="data.js"></script> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="buttongroups-container"> <div id="single-selection"></div> <div id="multiple-selection"></div> </div> <div class="buttongroups-container"> <div id="single-selection-styling-mode"></div> <div id="multiple-selection-styling-mode"></div> </div> </div> </body> </html>
.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: #ddd; }
const alignments = [ { icon: 'alignleft', alignment: 'left', hint: 'Align left', }, { icon: 'aligncenter', alignment: 'center', hint: 'Center', }, { icon: 'alignright', alignment: 'right', hint: 'Align right', }, { icon: 'alignjustify', alignment: 'justify', hint: 'Justify', }, ]; const fontStyles = [ { icon: 'bold', style: 'bold', hint: 'Bold', }, { icon: 'italic', style: 'italic', hint: 'Italic', }, { icon: 'underline', style: 'underline', hint: 'Underlined', }, { icon: 'strike', style: 'strike', hint: 'Strikethrough', }, ];