DataColumn
API reference › CSV Export › DataColumn
DataColumn is the default column type for CsvExporter.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attribute | string| | 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. Default: null. | DataColumn |
$content | callable(mixed, Column): mixed| | This is a callable that will be used to generate the content of each cell. Default: null. | Column |
$footer | string| | Footer cell content, or null to use the exporter fallback. Default: null. | Column |
$format | string| | Yii formatter name or format with arguments, such as ['date',. Default: 'raw'. | DataColumn |
$grid | CsvExporter | The exporter that owns this column. | Column |
$header | string| | Header cell content, or null to use the exporter fallback. Default: null. | Column |
$label | string| | Header 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-only | yii\| | Model whose attribute labels supply headers, or null to use humanized attribute names. | DataColumn |
$value | string| DataColumn): mixed| | An anonymous function or a string that is used to determine the value to display in the current column. Default: null. | DataColumn |
$visible | bool | Whether this column is visible. Defaults to true. Default: true. | Column |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
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\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
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 |
Property details
Section titled “Property details”$attribute
Section titled “$attribute ”public string|null $attribute = 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.
Also, if $label is not specified, the label associated with the attribute will be displayed.
$format
Section titled “$format ”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.
$value
Section titled “$value ”public string|callable(mixed, mixed, int, yii2\extensions\csvexport\DataColumn): mixed|null $value = nullAn 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.
Method details
Section titled “Method details”getDataCellValue()
Section titled “getDataCellValue() ”public function getDataCellValue(mixed $model, mixed $key, int $index): mixedReturns the data cell value.
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 unformatted value, or null when neither value nor attribute is set.
Throws
yii\base\InvalidConfigException: if an attribute is read from a row that is neither an array nor an object.
renderDataCellContent()
Section titled “renderDataCellContent() ”public function renderDataCellContent(mixed $model, mixed $key, int $index): mixedRenders the formatted cell value, or the result of content when it is set.
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 formatted value, the exporter’s nullDisplay for a null value, or the result of content.
Throws
yii\base\InvalidConfigException: if an attribute is read from a scalar row, or no exporter or formatter exists.
renderHeaderCellContent()
Section titled “renderHeaderCellContent() ”public function renderHeaderCellContent(): stringRenders 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
yii\base\InvalidConfigException: if the fallback is needed and the column has no exporter.
setLabelModel()
Section titled “setLabelModel() ”public function setLabelModel(yii\base\Model|null $model): voidSets the label context from the effective source of this export.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | yii\| | Model whose attribute labels supply headers, or null to use humanized attribute names. |