Class yii\grid\RadioButtonColumn
| 继承 | yii\grid\RadioButtonColumn » yii\grid\Column » yii\base\BaseObject |
|---|---|
| 实现 | yii\base\Configurable |
| 可用版本自 | 2.0.11 |
| 源码 | https://github.com/yiichina/yii2/blob/api/framework/grid/RadioButtonColumn.php |
RadioButtonColumn 在网格视图中显示一列单选按钮。
要将 RadioButtonColumn 添加到 yii\grid\GridView 中,请将其添加到 columns 的配置中,如下:
'columns' => [
// ...
[
'class' => 'yii\grid\RadioButtonColumn',
'radioOptions' => function ($model) {
return [
'value' => $model['value'],
'checked' => $model['value'] == 2
];
}
],
]
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $content | callable | 这是用于生成每个单元格内容的回调函数。
函数的写法如下:function ($model, $key, $index, $column)。
其中,$model,$key 和 $index 表示当前渲染行的模型,键和索引,
$column 是对 yii\grid\Column 对象的引用。 |
yii\grid\Column |
| $contentOptions | array|Closure | 数据单元标签的 HTML 属性。
这可以是属性数组或返回此类数组的匿名函数(Closure)。
函数的写法应该如下:function ($model, $key, $index, $column)。
其中,$model,$key 和 $index 表示当前渲染行的模型、键和索引,
$column 是对 yii\grid\Column 对象的引用。
函数可用于根据该行中的数据将不同的属性分配给不同的行。 |
yii\grid\Column |
| $filterOptions | array | 筛选单元格标签的 HTML 属性。 | yii\grid\Column |
| $footer | string | 页脚单元格内容。注意,它不是 HTML 编码的。 | yii\grid\Column |
| $footerOptions | array | The 页脚单元格标签的 HTML 属性。 | yii\grid\Column |
| $grid | yii\grid\GridView | 拥有此列的网格视图对象。 | yii\grid\Column |
| $header | string | 标题单元格内容。注意,它不是 HTML 编码的。 | yii\grid\Column |
| $headerOptions | array | 标题单元格标签的 HTML 属性。 | yii\grid\Column |
| $name | string | 单选按钮输入字段的名称。 | yii\grid\RadioButtonColumn |
| $options | array | 列组标签的 HTML 属性。 | yii\grid\Column |
| $radioOptions | array|Closure | 单选按钮的 HTML 属性。
这可以是属性数组或返回此类数组的匿名函数(Closure)。
该函数的写法应该如下:function ($model, $key, $index, $column)
其中,$model,$key 和 $index 表示当前渲染行的模型,键和索引,
$column 是对 yii\grid\RadioButtonColumn 对象的引用。
函数可用于根据该行中的数据将不同的属性分配给不同的行。
具体来说,如果希望为单选按钮设置不同的值,
可以按照如下的方法使用此选项:(在本例中使用模型的 name 属性)。
`php
'radioOptions' => function ($model, $key, $index, $column) {
return ['value' => $model->attribute];
}
` |
yii\grid\RadioButtonColumn |
| $visible | boolean | 列是否可见。默认为 true。 | yii\grid\Column |
公共方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| __call() | Calls the named method which is not a class method. | yii\base\BaseObject |
| __construct() | Constructor. | yii\base\BaseObject |
| __get() | Returns the value of an object property. | yii\base\BaseObject |
| __isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
| __set() | Sets value of an object property. | yii\base\BaseObject |
| __unset() | Sets an object property to null. | yii\base\BaseObject |
| canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
| canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
| className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
| hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
| hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
| init() | Initializes the object. | yii\grid\RadioButtonColumn |
| renderDataCell() | 渲染数据单元格。 | yii\grid\Column |
| renderFilterCell() | Renders the filter cell. | yii\grid\Column |
| renderFooterCell() | 渲染标题单元格。 | yii\grid\Column |
| renderHeaderCell() | Renders the header cell. | yii\grid\Column |
受保护的方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| getHeaderCellLabel() | 返回标题单元格标签。 可以重写此方法以自定义标题单元格的标签。 | yii\grid\Column |
| renderDataCellContent() | 渲染数据单元格内容。 | yii\grid\RadioButtonColumn |
| renderFilterCellContent() | 渲染过滤单元格内容。 默认实现只是渲染一个空格。 可以重写此方法以自定义过滤器单元的渲染(如果有)。 | yii\grid\Column |
| renderFooterCellContent() | 渲染页脚单元格内容。 默认实现只是渲染 $footer。 可以重写此方法以自定义页脚单元格的渲染。 | yii\grid\Column |
| renderHeaderCellContent() | 渲染过滤单元格。 默认实现只是渲染 $header。 可以重写此方法以自定义标题单元格的渲染。 | yii\grid\Column |
属性详情
单选按钮输入字段的名称。
单选按钮的 HTML 属性。 这可以是属性数组或返回此类数组的匿名函数(Closure)。
该函数的写法应该如下:function ($model, $key, $index, $column)
其中,$model,$key 和 $index 表示当前渲染行的模型,键和索引,
$column 是对 yii\grid\RadioButtonColumn 对象的引用。
函数可用于根据该行中的数据将不同的属性分配给不同的行。
具体来说,如果希望为单选按钮设置不同的值,
可以按照如下的方法使用此选项:(在本例中使用模型的 name 属性)。
'radioOptions' => function ($model, $key, $index, $column) {
return ['value' => $model->attribute];
}
参见 yii\helpers\Html::renderTagAttributes() 有关于如果渲染属性的详细信息。.
方法详情
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
| public void init() | ||
| throws | yii\base\InvalidConfigException | 如果 $name 没有设置抛出的异常。 |
|---|---|---|
渲染数据单元格内容。
| protected string renderDataCellContent($model, $key, $index) | ||
| $model | mixed | 数据模型 |
| $key | mixed | 与数据模型相关的键 |
| $index | integer | 由 yii\grid\GridView::$dataProvider 返回的模型数组中的数据模型的从零开始的索引。 |
| return | string | 渲染结果 |
|---|---|---|