Your search did not match any results.

Radio Group

The RadioGroup component contains a set of radio buttons and allows users to select one item from it. This demo illustrates how to bind the component to data, change the component layout, define a custom template, and handle the value change event.

Backend API
@{ var priorities = new[] { "Low", "Normal", "Urgent", "High" }; var priorityEntities = new[] { new { id = 0, text = "Low" }, new { id = 1, text = "Normal" }, new { id = 2, text = "Urgent" }, new { id = 3, text = "High" }, }; } <div class="form"> <div class="dx-fieldset"> <div class="dx-field"> <div class="dx-field-label">Default mode</div> <div class="dx-field-value"> @(Html.DevExtreme().RadioGroup() .Items(priorities) .Value("Low") ) </div> </div> <div class="dx-field"> <div class="dx-field-label">Disabled</div> <div class="dx-field-value"> @(Html.DevExtreme().RadioGroup() .Items(priorities) .Value("Normal") .Disabled(true) ) </div> </div> <div class="dx-field"> <div class="dx-field-label">Horizontal layout</div> <div class="dx-field-value"> @(Html.DevExtreme().RadioGroup() .Items(priorities) .Value("Low") .Layout(Orientation.Horizontal) ) </div> </div> <div class="dx-field"> <div class="dx-field-label">Custom item template</div> <div class="dx-field-value"> @(Html.DevExtreme().RadioGroup() .Items(priorities) .Value("Urgent") .ItemTemplate(new JS("radioGroupItemTemplate")) ) </div> </div> <div class="dx-field"> <div class="dx-field-label">Event handling</div> <div class="dx-field-value"> @(Html.DevExtreme().RadioGroup() .ID("radio-group-with-selection") .DataSource(priorityEntities) .ValueExpr("id") .DisplayExpr("text") .Value(0) .OnValueChanged("radioGroup_valueChanged") ) </div> </div> </div> <div id="tasks-list"> Tasks by selected priority: <ul id="list"> <li>Non-Compete Agreements</li> </ul> </div> </div> <script> function radioGroupItemTemplate(itemData, _, itemElement) { itemElement .parent().addClass(itemData.toLowerCase()) .text(itemData); } function radioGroup_valueChanged(e) { $("#list").children().remove(); $.each([{ subject: "Choose between PPO and HMO Health Plan", priority: 3 }, { subject: "Non-Compete Agreements", priority: 0 }, { subject: "Comment on Revenue Projections", priority: 1 }, { subject: "Sign Updated NDA", priority: 2 }, { subject: "Submit Questions Regarding New NDA", priority: 3 }, { subject: "Rollout of New Website and Marketing Brochures", priority: 3 }], function (_, item) { if(item.priority === e.value) { $("#list").append($("<li/>").text(item.subject)); } }); } </script>
using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class RadioGroupController : Controller { public ActionResult Overview() { return View(); } } }
.low.dx-radiobutton-checked .dx-radiobutton-icon .dx-radiobutton-icon-dot { background: gray; } .normal.dx-radiobutton-checked .dx-radiobutton-icon .dx-radiobutton-icon-dot { background: green; } .urgent.dx-radiobutton-checked .dx-radiobutton-icon .dx-radiobutton-icon-dot { background: orange; } .high.dx-radiobutton-checked .dx-radiobutton-icon .dx-radiobutton-icon-dot { background: red; } #radio-group-with-selection { margin-bottom: 10px; } #tasks-list { margin: 0 0 10px 10px; white-space: normal; } #list { margin: 10px 0 0 20px; padding-left: 0; text-align: left; }

Bind RadioGroup to Data

You can display RadioGroup items from the items array or a dataSource. If your data is an array of objects, use the displayExpr and valueExpr properties. displayExpr specifies a data source field that contains button captions. valueExpr specifies a data source field that supplies values to the value property when users select a button. Leave valueExpr unspecified if you need to supply the entire data object to the value property.

Configure the Layout

The RadioGroup supports horizontal (default for tablets) and vertical (default for other devices) layouts. To change the layout for all device types, specify the layout property.

Customize the Item Appearance

Define the itemTemplate to customize the item appearance. To customize an individual item, specify its template property.

Handle the Value Change Event

You can set the value property to one of the data source items to specify a predefined selection. Implement the onValueChanged function to handle value changes.