radio
List of radio input controls.
Please note - this property requires the Editor extension for DataTables.
Description
List of radio input controls (<input type="radio">) from which the end user can select a single option.
Options
This field type supports the following options (in addition to the default options):
options
The values and labels to be used in the list of radio inputs. This can be given in a number of different forms:
object- Name / value pairs, where the property name is used as the label and the value as the field value. For example:{ "Edinburgh": 51, "London": 76, ... }.array- An array of objects with the propertieslabelandvaluedefined. For example:[ { label: "Edinburgh", value: 51 }, { label: "London", value: 76 } ].array- An array of values (e.g. numbers, strings etc). Each element in the array will be used for both the label and the value. For example:[ "Edinburgh", "London" ].
Note: in v1.3 and earlier this was called ipOpts which is still supported for backwards compatibility.
optionsPair
- Type:
object - Default:
{label:'label', value:'value'} - Since: 1.4
If options is given as an array of objects, by default Editor will read the information for the label and value properties of the select input from the label and value properties of the data source object. This option provides the ability to alter those parameters by giving it as an object containing the properties label and value itself, the values of which indicate the properties that should be read from the data source object. For example you might use { label: 'name', value: 'id' } - see below for a complete example.
unselectedValue
When there a radio option isn't selected, it will have no value. This option provides the ability to assign a value to the field when there isn't a selection.
Methods
This field type supports the following methods (in addition to the default methods):
field().update( options [, append ] )
Update the options in the list of radio inputs with the options passed in as the first parameter to the function.
Note that the existing options will be entirely replaced by the options given to this method.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | options | No | |
Options to display. The data structure given should match that used by the Optionally, each object in an array given as the options to display can have an | |||
| 2 | append | Yes - default:false | |
Since 1.6: Flag to indicate if the new options should be appended to the existing list of options, or if they should entirely replace the current list (which is the default action). | |||
Returns:
DataTable.Editor.Field:
The field instance is returned to allow method chaining.
Examples
Basic initialisation (array data source):
editor.add({
type: 'radio',
label: 'Year:',
name: 'year',
options: [2012, 2013, 2014, 2015]
});Use an array of objects with default label and value properties:
editor.add({
type: 'radio',
label: 'Locations:',
name: 'locations',
options: [
{ label: 'Edinburgh', value: 51 },
{ label: 'London', value: 76 }
]
});Use an array of objects with specified label and value properties:
editor.add({
type: 'radio',
label: 'Locations:',
name: 'locations',
options: [
{ name: 'Edinburgh', id: 51 },
{ name: 'London', id: 76 }
],
optionsPair: {
label: 'name',
value: 'id'
}
});Use an object data source:
editor.add({
type: 'checkbox',
label: 'Location:',
name: 'location',
options: {
Edinburgh: 51,
London: 76
}
});Update the options available using the update() method.:
editor.field('location').update({
Edinburgh: 51,
London: 76,
Paris: 4,
'New York': 32
});