Class yii\grid\SerialColumn
| 继承 | yii\grid\SerialColumn » yii\grid\Column » yii\base\BaseObject |
|---|---|
| 实现 | yii\base\Configurable |
| 可用版本自 | 2.0 |
| 源码 | https://github.com/yiichina/yii2/blob/api/framework/grid/SerialColumn.php |
SerialColumn 显示一列的行号(基于1)。
向 yii\grid\GridView 添加 SerialColumn,将其添加到 columns 的配置中,如下所示:
'columns' => [
// ...
[
'class' => 'yii\grid\SerialColumn',
// you may configure additional properties here
],
]
有关于 SerialColumn 更多的细节和用法,请参阅 guide article on data widgets。
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $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\SerialColumn |
| $headerOptions | array | 标题单元格标签的 HTML 属性。 | yii\grid\Column |
| $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\base\BaseObject |
| 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\SerialColumn |
| renderFilterCellContent() | 渲染过滤单元格内容。 默认实现只是渲染一个空格。 可以重写此方法以自定义过滤器单元的渲染(如果有)。 | yii\grid\Column |
| renderFooterCellContent() | 渲染页脚单元格内容。 默认实现只是渲染 $footer。 可以重写此方法以自定义页脚单元格的渲染。 | yii\grid\Column |
| renderHeaderCellContent() | 渲染过滤单元格。 默认实现只是渲染 $header。 可以重写此方法以自定义标题单元格的渲染。 | yii\grid\Column |
属性详情
方法详情
渲染数据单元格内容。
| protected string renderDataCellContent($model, $key, $index) | ||
| $model | mixed | 数据模型 |
| $key | mixed | 与数据模型相关的键 |
| $index | integer | 由 yii\grid\GridView::$dataProvider 返回的模型数组中的数据模型的从零开始的索引。 |
| return | string | 渲染结果 |
|---|---|---|