Skip to content
PHP Ecosystem
Explore

Column

API reference › yii › grid › Column

classyii\grid\Column
Extendsyii\base\BaseObject
Implementsyii\base\Configurable
Since2.0
Sourceframework/grid/Column.php
5 subclasses

Column is the base class of all GridView column classes.

For more details and usage information on Column, see the guide article on data widgets.

PropertyTypeDescriptionDefined by
$contentcallableThis is a callable that will be used to generate the content of each cell. Default: null.Column
$contentOptionsarray|ClosureThe HTML attributes for the data cell tag. Default: [].Column
$filterOptionsarrayThe HTML attributes for the filter cell tag. Default: [].Column
$footerstringThe footer cell content. Default: null.Column
$footerOptionsarrayThe HTML attributes for the footer cell tag. Default: [].Column
$gridGridViewThe grid view object that owns this column. Default: null.Column
$headerstring|nullThe header cell content. Default: null.Column
$headerOptionsarrayThe HTML attributes for the header cell tag. Default: [].Column
$optionsarrayThe HTML attributes for the column group tag. Default: [].Column
$visibleboolWhether this column is visible. Default: true.Column
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.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() staticReturns 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()Renders a data cell.Column
renderFilterCell()Renders the filter cell.Column
renderFooterCell()Renders the footer cell.Column
renderHeaderCell()Renders the header cell.Column
getHeaderCellLabel() protectedReturns header cell label.Column
renderDataCellContent() protectedRenders the data cell content.Column
renderFilterCellContent() protectedRenders the filter cell content.Column
renderFooterCellContent() protectedRenders the footer cell content.Column
renderHeaderCellContent() protectedRenders the header cell content.Column
public callable $content = null

This is a callable that will be used to generate the content of each cell.

The signature of the function should be the following: 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 Column object.

public array|Closure $contentOptions = []

The HTML attributes for the data cell tag.

This can either be an array of attributes or an anonymous function (Closure) that returns such an array. The signature of the function should be the following: 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 Column object. A function may be used to assign different attributes to different rows based on the data in that row.

public string $footer = null

The footer cell content.

Note that it will not be HTML-encoded.

public string|null $header = null

The header cell content.

Note that it will not be HTML-encoded.

public bool $visible = true

Whether this column is visible.

Defaults to true.

public function renderDataCell(mixed $model, mixed $key, int $index): string

Renders a data cell.

Parameters

ParameterTypeDescription
$modelmixedThe data model being rendered
$keymixedThe key associated with the data model
$indexintThe zero-based index of the data item among the item array returned by GridView::$dataProvider.

Returns

string: The rendering result

public function renderFilterCell(): mixed

Renders the filter cell.

Returns

mixed

public function renderFooterCell(): mixed

Renders the footer cell.

Returns

mixed

public function renderHeaderCell(): mixed

Renders the header cell.

Returns

mixed

protected function getHeaderCellLabel(): string

Returns header cell label.

This method may be overridden to customize the label of the header cell.

Returns

string: Label

Since

2.0.8

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

Renders the data cell content.

Parameters

ParameterTypeDescription
$modelmixedThe data model
$keymixedThe key associated with the data model
$indexintThe zero-based index of the data model among the models array returned by GridView::$dataProvider.

Returns

string: The rendering result

protected function renderFilterCellContent(): string

Renders the filter cell content.

The default implementation simply renders a space. This method may be overridden to customize the rendering of the filter cell (if any).

Returns

string: The rendering result

protected function renderFooterCellContent(): string

Renders the footer cell content.

The default implementation simply renders $footer. This method may be overridden to customize the rendering of the footer cell.

Returns

string: The rendering result

protected function renderHeaderCellContent(): string

Renders the header cell content.

The default implementation simply renders $header. This method may be overridden to customize the rendering of the header cell.

Returns

string: The rendering result