Skip to content
PHP Ecosystem
Explore

DataColumn

API reference › CSV Export › DataColumn

classyii2\extensions\csvexport\DataColumn
ExtendsColumn » yii\base\BaseObject
Implementsyii\base\Configurable
Sourcesrc/DataColumn.php

DataColumn is the default column type for CsvExporter.

PropertyTypeDescriptionDefined by
$attributestring|nullThe attribute name associated with this column. When neither $content nor $value is specified, the value of the specified attribute will be retrieved from each data model and displayed. Default: null.DataColumn
$contentcallable(mixed, mixed, int, Column): mixed|nullThis is a callable that will be used to generate the content of each cell. Default: null.Column
$footerstring|nullFooter cell content, or null to use the exporter fallback. Default: null.Column
$formatstring|array<int, mixed>Yii formatter name or format with arguments, such as ['date', 'php:Y-m-d']. Default: 'raw'.DataColumn
$gridCsvExporterThe exporter that owns this column.Column
$headerstring|nullHeader cell content, or null to use the exporter fallback. Default: null.Column
$labelstring|nullHeader label when no explicit header is set. When unset, the column uses the label model’s attribute label or humanizes the attribute name. Default: null.DataColumn
$labelModel write-onlyyii\base\Model|nullModel whose attribute labels supply headers, or null to use humanized attribute names.DataColumn
$valuestring|callable(mixed, mixed, int, DataColumn): mixed|nullAn anonymous function or a string that is used to determine the value to display in the current column. Default: null.DataColumn
$visibleboolWhether this column is visible. Defaults to true. 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
getDataCellValue()Returns the data cell value.DataColumn
getGrid()Returns the exporter that owns this column.Column
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
renderDataCellContent()Renders the formatted cell value, or the result of content when it is set.DataColumn
renderFooterCellContent()Renders the footer cell using configured text or the exporter fallback.Column
renderHeaderCellContent()Renders the first available of header, label, the model’s attribute label and a humanized attribute name.DataColumn
setGrid()Sets the exporter that owns this column.Column
setLabelModel()Sets the label context from the effective source of this export.DataColumn
public string|null $attribute = null

The attribute name associated with this column. When neither $content nor $value is specified, the value of the specified attribute will be retrieved from each data model and displayed.

Also, if $label is not specified, the label associated with the attribute will be displayed.

public string|array<int, mixed> $format = 'raw'

Yii formatter name or format with arguments, such as ['date', 'php:Y-m-d'].

The default raw format leaves values unformatted.

public string|callable(mixed, mixed, int, yii2\extensions\csvexport\DataColumn): mixed|null $value = null

An anonymous function or a string that is used to determine the value to display in the current column.

If this is an anonymous function, it will be called for each row and the return value will be used as the value to display for every data model. The signature of this function should be: 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 DataColumn object.

You may also set this property to a string representing the attribute name to be displayed in this column.

If this is not set, $model[$attribute] will be used to obtain the value, where $attribute is the value of $attribute.

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

Returns the data cell value.

Parameters

ParameterTypeDescription
$modelmixedData row from the effective source.
$keymixedKey associated with the data row.
$indexintZero-based row index across the export.

Returns

mixed: The unformatted value, or null when neither value nor attribute is set.

Throws

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

Renders the formatted cell value, or the result of content when it is set.

Parameters

ParameterTypeDescription
$modelmixedData row from the effective source.
$keymixedKey associated with the data row.
$indexintZero-based row index across the export.

Returns

mixed: The formatted value, the exporter’s nullDisplay for a null value, or the result of content.

Throws

public function renderHeaderCellContent(): string

Renders the first available of header, label, the model’s attribute label and a humanized attribute name.

Returns

string: The header text, or the exporter’s empty-cell value when nothing names the column.

Throws

public function setLabelModel(yii\base\Model|null $model): void

Sets the label context from the effective source of this export.

Parameters

ParameterTypeDescription
$modelyii\base\Model|nullModel whose attribute labels supply headers, or null to use humanized attribute names.