Class yii\grid\CheckboxColumn
| 继承 | yii\grid\CheckboxColumn » yii\grid\Column » yii\base\BaseObject |
|---|---|
| 实现 | yii\base\Configurable |
| 可用版本自 | 2.0 |
| 源码 | https://github.com/yiichina/yii2/blob/api/framework/grid/CheckboxColumn.php |
CheckboxColumn 在网格视图中显示一列复选框。
将 CheckboxColumn 添加到 yii\grid\GridView,请将其添加到 columns 配置中,如下所示:
'columns' => [
// ...
[
'class' => 'yii\grid\CheckboxColumn',
// you may configure additional properties here
],
]
用户可以单击复选框来选择网格的行。 可以通过调用以下的 JavaScript 代码来获取所选行:
var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows
关于 CheckboxColumn 的更多细节和用法,请参阅 guide article on data widgets。
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $checkboxOptions | array|Closure | 复选框的 HTML 属性。
这可以是属性数组,也可以是返回这样一个数组的匿名函数(Closure)。
函数的写法应该为:function ($model, $key, $index, $column)。
其中,$model,$key 和 $index 表示当前渲染行的模型,键和索引,
$column 是对 yii\grid\CheckboxColumn 对象的引用。
可以使用函数基于该行中的数据将不同的属性分配给不同的行。
具体来说,如果要为复选框设置不同的值,
可以按照以下方式使用此选项(在此实例中使用模型的 name 属性)。
`php
'checkboxOptions' => function ($model, $key, $index, $column) {
return ['value' => $model->name];
}
` |
yii\grid\CheckboxColumn |
| $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 |
| $cssClass | string | 将用于查找复选框的 css 类。 | yii\grid\CheckboxColumn |
| $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 |
| $multiple | boolean | 是否可以选择多行。默认为 true。 |
yii\grid\CheckboxColumn |
| $name | string | 复选框输入字段的名称。将附加 [] 以确保它是一个数组。 |
yii\grid\CheckboxColumn |
| $options | array | 列组标签的 HTML 属性。 | yii\grid\Column |
| $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\CheckboxColumn |
| registerClientScript() | 注册所需的 JavaScript。 | yii\grid\CheckboxColumn |
| 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 |
| getHeaderCheckBoxName() | 返回标题复选框名称。 | yii\grid\CheckboxColumn |
| renderDataCellContent() | 渲染数据单元格内容。 | yii\grid\CheckboxColumn |
| renderFilterCellContent() | 渲染过滤单元格内容。 默认实现只是渲染一个空格。 可以重写此方法以自定义过滤器单元的渲染(如果有)。 | yii\grid\Column |
| renderFooterCellContent() | 渲染页脚单元格内容。 默认实现只是渲染 $footer。 可以重写此方法以自定义页脚单元格的渲染。 | yii\grid\Column |
| renderHeaderCellContent() | 渲染标题单元格内容。 默认实现只是渲染 $header。 可以重写此方法来自定义标题单元格的渲染。 | yii\grid\CheckboxColumn |
属性详情
复选框的 HTML 属性。
这可以是属性数组,也可以是返回这样一个数组的匿名函数(Closure)。
函数的写法应该为:function ($model, $key, $index, $column)。
其中,$model,$key 和 $index 表示当前渲染行的模型,键和索引,
$column 是对 yii\grid\CheckboxColumn 对象的引用。
可以使用函数基于该行中的数据将不同的属性分配给不同的行。
具体来说,如果要为复选框设置不同的值,
可以按照以下方式使用此选项(在此实例中使用模型的 name 属性)。
'checkboxOptions' => function ($model, $key, $index, $column) {
return ['value' => $model->name];
}
参见 yii\helpers\Html::renderTagAttributes() 有关如何渲染属性的详细信息。.
将用于查找复选框的 css 类。
是否可以选择多行。默认为 true。
复选框输入字段的名称。将附加 [] 以确保它是一个数组。
方法详情
返回标题复选框名称。
| protected string getHeaderCheckBoxName() | ||
| return | string | 标题复选框名称 |
|---|---|---|
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 | if $name is not set. |
|---|---|---|
注册所需的 JavaScript。
| public void registerClientScript() |
渲染数据单元格内容。
| protected string renderDataCellContent($model, $key, $index) | ||
| $model | mixed | 数据模型 |
| $key | mixed | 与数据模型相关的键 |
| $index | integer | 由 yii\grid\GridView::$dataProvider 返回的模型数组中的数据模型的从零开始的索引。 |
| return | string | 渲染结果 |
|---|---|---|
渲染标题单元格内容。 默认实现只是渲染 $header。 可以重写此方法来自定义标题单元格的渲染。
| protected string renderHeaderCellContent() | ||
| return | string | 渲染结果 |
|---|---|---|