# Column

> Column is the base class of all yii2\extensions\csvexport\CsvExporter column classes.

[API reference](/docs/api/index.md) › [CSV Export](/docs/extensions/csv-export/reference/index.md) › Column

| class | `yii2\extensions\csvexport\Column` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/Column.php`](https://github.com/yii2-extensions/csv-export/blob/main/src/Column.php#L15) |

2 subclasses:

- [`DataColumn`](/docs/extensions/csv-export/reference/datacolumn/index.md)
- [`SerialColumn`](/docs/extensions/csv-export/reference/serialcolumn/index.md)

Column is the base class of all [`CsvExporter`](/docs/extensions/csv-export/reference/csvexporter/index.md) column classes.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$content`](#property-content) | `callable(mixed, mixed, int,` [`Column`](/docs/extensions/csv-export/reference/column/index.md)`): mixed\|null` | This is a callable that will be used to generate the content of each cell. Default: `null`. | `Column` |
| <span id="property-footer"></span>`$footer` | `string\|null` | Footer cell content, or `null` to use the exporter fallback. Default: `null`. | `Column` |
| <span id="property-grid"></span>`$grid` | [`CsvExporter`](/docs/extensions/csv-export/reference/csvexporter/index.md) | The exporter that owns this column. | `Column` |
| <span id="property-header"></span>`$header` | `string\|null` | Header cell content, or `null` to use the exporter fallback. Default: `null`. | `Column` |
| <span id="property-visible"></span>`$visible` | `bool` | Whether this column is visible. Defaults to true. 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) |
| [`getGrid()`](#method-getGrid) | Returns the exporter that owns this column. | `Column` |
| <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) |
| [`renderDataCellContent()`](#method-renderDataCellContent) | Renders a data cell using the content callback or the exporter fallback. | `Column` |
| [`renderFooterCellContent()`](#method-renderFooterCellContent) | Renders the footer cell using configured text or the exporter fallback. | `Column` |
| [`renderHeaderCellContent()`](#method-renderHeaderCellContent) | Renders the header cell using configured text or the exporter fallback. | `Column` |
| [`setGrid()`](#method-setGrid) | Sets the exporter that owns this column. | `Column` |

## Property details

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

```php
public callable(mixed, mixed, int, yii2\extensions\csvexport\Column): mixed|null $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/extensions/csv-export/reference/column/index.md) object.

## Method details

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

```php
public function getGrid(): yii2\extensions\csvexport\CsvExporter
```

Returns the exporter that owns this column.

**Returns**

[`CsvExporter`](/docs/extensions/csv-export/reference/csvexporter/index.md): The owning exporter.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the column was not assigned to an exporter.

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

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

Renders a data cell using the content callback or the exporter fallback.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | `mixed` | Data row from the effective source. |
| `$key` | `mixed` | Key associated with the data row. |
| `$index` | `int` | Zero-based row index across the export. |

**Returns**

`mixed`: The result of `content`, or the exporter's empty-cell value when `content` is unset.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the fallback is needed and the column has no exporter.

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

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

Renders the footer cell using configured text or the exporter fallback.

**Returns**

`string`: The footer text, or the exporter's empty-cell value when the footer is unset or blank.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the fallback is needed and the column has no exporter.

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

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

Renders the header cell using configured text or the exporter fallback.

**Returns**

`string`: The header text, or the exporter's empty-cell value when the header is unset or blank.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the fallback is needed and the column has no exporter.

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

```php
public function setGrid(yii2\extensions\csvexport\CsvExporter $grid): void
```

Sets the exporter that owns this column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$grid` | [`CsvExporter`](/docs/extensions/csv-export/reference/csvexporter/index.md) | Exporter that renders this column. |