Angular RadioGroup API
The RadioGroup is a widget that contains a set of radio buttons and allows an end user to make a single selection from the set.
DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.
The following code shows how to create the RadioGroup widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.
jQuery
var radioGroupItems = [ { text: "Item 1", color: "grey" }, { text: "Item 2", color: "green" }, { text: "Item 3", color: "yellow" }, { text: "Item 4", color: "red" } ]; $(function () { $("#radioGroup").dxRadioGroup({ dataSource: radioGroupItems, displayExpr: "text", valueExpr: "color", value: "green" }); });
<div id="radioGroup"></div>
Angular
<dx-radio-group [dataSource]="radioGroupItems" displayExpr="text" valueExpr="color" value="green"> </dx-radio-group>
import { DxRadioGroupModule } from "devextreme-angular" // ... export class AppComponent { radioGroupItems = [ { text: "Item 1", color: "grey" }, { text: "Item 2", color: "green" }, { text: "Item 3", color: "yellow" }, { text: "Item 4", color: "red" } ]; } @NgModule({ imports: [ // ... DxRadioGroupModule ], // ... })
AngularJS
<div ng-controller="DemoController"> <div dx-radio-group="{ dataSource: radioGroupItems, displayExpr: 'text', valueExpr: 'color', value: 'green' }"></div> </div>
angular.module("DemoApp", ["dx"]) .controller("DemoController", function DemoController($scope) { $scope.radioGroupItems = [ { text: "Item 1", color: "grey" }, { text: "Item 2", color: "green" }, { text: "Item 3", color: "yellow" }, { text: "Item 4", color: "red" } ]; });
Knockout
<div data-bind="dxRadioGroup: { dataSource: radioGroupItems, displayExpr: 'text', valueExpr: 'color', value: 'green' }"></div>
var viewModel = { radioGroupItems: [ { text: "Item 1", color: "grey" }, { text: "Item 2", color: "green" }, { text: "Item 3", color: "yellow" }, { text: "Item 4", color: "red" } ] }; ko.applyBindings(viewModel);
ASP.NET MVC Controls
@(Html.DevExtreme().RadioGroup() .ID("radioGroup") .DisplayExpr("text") .ValueExpr("color") .Value("green") .DataSource(new object[] { new { text = "Item 1", color = "grey" }, new { text = "Item 2", color = "green" }, new { text = "Item 3", color = "yellow" }, new { text = "Item 4", color = "red" } }) )
@(Html.DevExtreme().RadioGroup() _ .ID("radioGroup") _ .DisplayExpr("text") _ .ValueExpr("color") _ .Value("green") _ .DataSource({ New With { .text = "Item 1", .color = "grey" }, New With { .text = "Item 2", .color = "green" }, New With { .text = "Item 3", .color = "yellow" }, New With { .text = "Item 4", .color = "red" } }) )
See Also
Properties
Name | Description |
---|---|
accessKey |
Specifies the shortcut key that sets focus on the widget. |
activeStateEnabled |
Specifies whether or not the widget changes its state when interacting with a user. |
dataSource |
A data source used to fetch data the widget should display. |
disabled |
Specifies whether the widget responds to user interaction. |
displayExpr |
Specifies the name of the data source item field whose value is displayed by the widget. |
elementAttr |
Specifies the attributes to be attached to the widget's root element. |
focusStateEnabled |
Specifies whether the widget can be focused using keyboard navigation. |
height |
Specifies the widget's height. |
hint |
Specifies text for a hint that appears when a user pauses on the widget. |
hoverStateEnabled |
Specifies whether the widget changes its state when a user pauses on it. |
isValid |
Specifies whether the editor's value is valid. |
items |
An array of items displayed by the widget. |
itemTemplate |
Specifies a custom template for items. |
layout |
Specifies the radio group layout. |
name |
The value to be assigned to the |
onContentReady |
A function that is executed when the widget's content is ready and each time the content is changed. |
onDisposing |
A function that is executed before the widget is disposed of. |
onInitialized |
A function that is executed only once, after the widget is initialized. |
onOptionChanged |
A function that is executed after a widget option is changed. |
onValueChanged |
A function that is executed after the widget's value is changed. |
readOnly |
A Boolean value specifying whether or not the widget is read-only. |
rtlEnabled |
Switches the widget to a right-to-left representation. |
tabIndex |
Specifies the number of the element when the Tab key is used for navigating. |
validationError |
Specifies information on the validation error when using a custom validation engine. Should be changed at runtime along with the isValid option. |
validationMessageMode |
Specifies how the message about the validation rules that are not satisfied by this editor's value is displayed. |
value |
Specifies the currently selected value. |
valueExpr |
Specifies which data field provides the widget's value. When this option is not set, the value is the entire data object. |
visible |
Specifies whether the widget is visible. |
width |
Specifies the widget's width. |
Methods
Name | Description |
---|---|
beginUpdate() |
Prevents the widget from refreshing until the endUpdate() method is called. |
defaultOptions(rule) |
Specifies the device-dependent default configuration options for this component. |
dispose() |
Disposes of all the resources allocated to the RadioGroup instance. |
element() |
Gets the root widget element. |
endUpdate() |
Refreshes the widget after a call of the beginUpdate() method. |
focus() |
Sets focus on the widget. |
getDataSource() |
Gets the DataSource instance. |
getInstance(element) |
Gets the instance of a widget found using its DOM node. |
instance() |
Gets the widget's instance. Use it to access other methods of the widget. |
off(eventName) |
Detaches all event handlers from a single event. |
off(eventName, eventHandler) |
Detaches a particular event handler from a single event. |
on(eventName, eventHandler) |
Subscribes to an event. |
on(events) |
Subscribes to events. |
option() |
Gets all widget options. |
option(optionName) |
Gets the value of a single option. |
option(optionName, optionValue) |
Updates the value of a single option. |
option(options) |
Updates the values of several options. |
registerKeyHandler(key, handler) |
Registers a handler to be executed when a user presses a specific key. |
repaint() |
Repaints the widget without reloading data. Call it to update the widget's markup. |
reset() |
Resets the value option to the default value. |
Events
Name | Description |
---|---|
contentReady |
Raised when the widget's content is ready. |
disposing |
Raised before the widget is disposed of. |
initialized |
Raised only once, after the widget is initialized. |
optionChanged |
Raised after a widget option is changed. |
valueChanged |
Raised after the widget's value is changed. |
Default Item Template
By default, a predefined item template is applied to display the items of this widget. This template is based on certain fields of the data source provided for this widget. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom item template based on these or other fields of your data source.
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.