# Column

> Column is the base class of all yii\grid\GridView column classes.

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

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

5 subclasses:

- [`ActionColumn`](/docs/api/yii/grid/actioncolumn/index.md)
- [`CheckboxColumn`](/docs/api/yii/grid/checkboxcolumn/index.md)
- [`DataColumn`](/docs/api/yii/grid/datacolumn/index.md)
- [`RadioButtonColumn`](/docs/api/yii/grid/radiobuttoncolumn/index.md)
- [`SerialColumn`](/docs/api/yii/grid/serialcolumn/index.md)

Column is the base class of all [`GridView`](/docs/api/yii/grid/gridview/index.md) column classes.

For more details and usage information on Column, see the [guide article on data widgets](/docs/guide/output-data-widgets/index.md).

## Properties

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

## 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) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`renderDataCell()`](#method-renderDataCell) | Renders a data cell. | `Column` |
| [`renderFilterCell()`](#method-renderFilterCell) | Renders the filter cell. | `Column` |
| [`renderFooterCell()`](#method-renderFooterCell) | Renders the footer cell. | `Column` |
| [`renderHeaderCell()`](#method-renderHeaderCell) | Renders the header cell. | `Column` |
| [`getHeaderCellLabel()`](#method-getHeaderCellLabel) protected | Returns header cell label. | `Column` |
| [`renderDataCellContent()`](#method-renderDataCellContent) protected | Renders the data cell content. | `Column` |
| [`renderFilterCellContent()`](#method-renderFilterCellContent) protected | Renders the filter cell content. | `Column` |
| [`renderFooterCellContent()`](#method-renderFooterCellContent) protected | Renders the footer cell content. | `Column` |
| [`renderHeaderCellContent()`](#method-renderHeaderCellContent) protected | Renders the header cell content. | `Column` |

## Property details

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

```php
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`](/docs/api/yii/grid/column/index.md) object.

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

```php
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`](https://www.php.net/manual/en/class.closure.php)) 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`](/docs/api/yii/grid/column/index.md) object.
A function may be used to assign different attributes to different rows based on the data in that row.

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

```php
public string $footer = null
```

The footer cell content.

Note that it will not be HTML-encoded.

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

```php
public string|null $header = null
```

The header cell content.

Note that it will not be HTML-encoded.

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

```php
public bool $visible = true
```

Whether this column is visible.

Defaults to true.

## Method details

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

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

Renders a data cell.

**Parameters**

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

**Returns**

`string`: The rendering result

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

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

Renders the filter cell.

**Returns**

`mixed`

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

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

Renders the footer cell.

**Returns**

`mixed`

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

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

Renders the header cell.

**Returns**

`mixed`

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

```php
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

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

```php
protected function renderDataCellContent(mixed $model, mixed $key, int $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` | `int` | 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

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

```php
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

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

```php
protected function renderFooterCellContent(): string
```

Renders the footer cell content.

The default implementation simply renders [`$footer`](/docs/api/yii/grid/column/index.md#property-footer).
This method may be overridden to customize the rendering of the footer cell.

**Returns**

`string`: The rendering result

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

```php
protected function renderHeaderCellContent(): string
```

Renders the header cell content.

The default implementation simply renders [`$header`](/docs/api/yii/grid/column/index.md#property-header).
This method may be overridden to customize the rendering of the header cell.

**Returns**

`string`: The rendering result