# RadioButtonColumn

> RadioButtonColumn displays a column of radio buttons in a grid view.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [grid](/docs/api/yii/grid/index.md) › RadioButtonColumn

| class | `yii\grid\RadioButtonColumn` |
| --- | --- |
| Extends | [`Column`](/docs/api/yii/grid/column/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0.11 |
| Source | [`framework/grid/RadioButtonColumn.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/grid/RadioButtonColumn.php#L38) |

RadioButtonColumn displays a column of radio buttons in a grid view.

To add a RadioButtonColumn to the [`GridView`](/docs/api/yii/grid/gridview/index.md), add it to the [columns](/docs/api/yii/grid/gridview/index.md#property-columns) configuration as follows:

```
'columns' => [
    // ...
    [
        'class' => 'yii\grid\RadioButtonColumn',
        'radioOptions' => function ($model) {
             return [
                 'value' => $model['value'],
                 'checked' => $model['value'] == 2
             ];
         }
    ],
]
```

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-content"></span>[`$content`](/docs/api/yii/grid/column/index.md#property-content) | `callable` | This is a callable that will be used to generate the content of each cell. Default: `null`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-contentOptions"></span>[`$contentOptions`](/docs/api/yii/grid/column/index.md#property-contentOptions) | `array\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | The HTML attributes for the data cell tag. Default: `[]`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-filterOptions"></span>[`$filterOptions`](/docs/api/yii/grid/column/index.md#property-filterOptions) | `array` | The HTML attributes for the filter cell tag. Default: `[]`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-footer"></span>[`$footer`](/docs/api/yii/grid/column/index.md#property-footer) | `string` | The footer cell content. Default: `null`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-footerOptions"></span>[`$footerOptions`](/docs/api/yii/grid/column/index.md#property-footerOptions) | `array` | The HTML attributes for the footer cell tag. Default: `[]`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-grid"></span>[`$grid`](/docs/api/yii/grid/column/index.md#property-grid) | [`GridView`](/docs/api/yii/grid/gridview/index.md) | The grid view object that owns this column. Default: `null`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-header"></span>[`$header`](/docs/api/yii/grid/column/index.md#property-header) | `string\|null` | The header cell content. Default: `null`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-headerOptions"></span>[`$headerOptions`](/docs/api/yii/grid/column/index.md#property-headerOptions) | `array` | The HTML attributes for the header cell tag. Default: `[]`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="property-name"></span>`$name` | `string` | The name of the input radio button input fields. Default: `'radioButtonSelection'`. | `RadioButtonColumn` |
| <span id="property-options"></span>[`$options`](/docs/api/yii/grid/column/index.md#property-options) | `array` | The HTML attributes for the column group tag. Default: `[]`. | [`Column`](/docs/api/yii/grid/column/index.md) |
| [`$radioOptions`](#property-radioOptions) | `array\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | The HTML attributes for the radio buttons. Default: `[]`. | `RadioButtonColumn` |
| <span id="property-visible"></span>[`$visible`](/docs/api/yii/grid/column/index.md#property-visible) | `bool` | Whether this column is visible. Default: `true`. | [`Column`](/docs/api/yii/grid/column/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`init()`](#method-init) | Initializes the object. | `RadioButtonColumn` |
| <span id="method-renderDataCell"></span>[`renderDataCell()`](/docs/api/yii/grid/column/index.md#method-renderDataCell) | Renders a data cell. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-renderFilterCell"></span>[`renderFilterCell()`](/docs/api/yii/grid/column/index.md#method-renderFilterCell) | Renders the filter cell. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-renderFooterCell"></span>[`renderFooterCell()`](/docs/api/yii/grid/column/index.md#method-renderFooterCell) | Renders the footer cell. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-renderHeaderCell"></span>[`renderHeaderCell()`](/docs/api/yii/grid/column/index.md#method-renderHeaderCell) | Renders the header cell. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-getHeaderCellLabel"></span>[`getHeaderCellLabel()`](/docs/api/yii/grid/column/index.md#method-getHeaderCellLabel) protected | Returns header cell label. | [`Column`](/docs/api/yii/grid/column/index.md) |
| [`renderDataCellContent()`](#method-renderDataCellContent) protected | Renders the data cell content. | `RadioButtonColumn` |
| <span id="method-renderFilterCellContent"></span>[`renderFilterCellContent()`](/docs/api/yii/grid/column/index.md#method-renderFilterCellContent) protected | Renders the filter cell content. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-renderFooterCellContent"></span>[`renderFooterCellContent()`](/docs/api/yii/grid/column/index.md#method-renderFooterCellContent) protected | Renders the footer cell content. | [`Column`](/docs/api/yii/grid/column/index.md) |
| <span id="method-renderHeaderCellContent"></span>[`renderHeaderCellContent()`](/docs/api/yii/grid/column/index.md#method-renderHeaderCellContent) protected | Renders the header cell content. | [`Column`](/docs/api/yii/grid/column/index.md) |

## Property details

### $radioOptions <span id="property-radioOptions"></span>

```php
public array|Closure $radioOptions = []
```

The HTML attributes for the radio buttons.

This can either be an array of
attributes or an anonymous function ([`Closure`](https://www.php.net/manual/en/class.closure.php)) returning such an array.

The signature of the function should be as follows: `function ($model, $key, $index, $column)`
where `$model`, `$key`, and `$index` refer to the model, key and index of the row currently being rendered
and `$column` is a reference to the [`RadioButtonColumn`](/docs/api/yii/grid/radiobuttoncolumn/index.md) object.

A function may be used to assign different attributes to different rows based on the data in that row.
Specifically if you want to set a different value for the radio button you can use this option
in the following way (in this example using the `name` attribute of the model):

```
'radioOptions' => function ($model, $key, $index, $column) {
    return ['value' => $model->attribute];
}
```

## Method details

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the
given configuration.

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if [`$name`](/docs/api/yii/grid/radiobuttoncolumn/index.md#property-name) is not set.

### renderDataCellContent() <span id="method-renderDataCellContent"></span>

```php
protected function renderDataCellContent(mixed $model, mixed $key, mixed $index): string
```

Renders the data cell content.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | `mixed` | The data model |
| `$key` | `mixed` | The key associated with the data model |
| `$index` | `mixed` | The zero-based index of the data model among the models array returned by [`GridView::$dataProvider`](/docs/api/yii/widgets/baselistview/index.md#property-dataProvider). |

**Returns**

`string`: The rendering result