Final Class Yiisoft\Yii\DataView\GridView\Column\DataColumn
| Inheritance | Yiisoft\Yii\DataView\GridView\Column\DataColumn |
|---|---|
| Implements | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
DataColumn is the default column type for the Yiisoft\Yii\DataView\GridView\GridView widget.
A simple data column definition refers to an attribute in the GridView's data provider.
Psalm Types
| Name | Value |
|---|---|
| FilterEmptyCallable | callable |
Public Properties
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Creates a new DataColumn instance. |
Yiisoft\Yii\DataView\GridView\Column\DataColumn |
| getRenderer() | Yiisoft\Yii\DataView\GridView\Column\DataColumn | |
| isVisible() | Yiisoft\Yii\DataView\GridView\Column\DataColumn |
Property Details
Additional CSS class for the body cells.
Method Details
Creates a new DataColumn instance.
// Basic usage
$column = new DataColumn(
property: 'username',
header: 'User',
withSorting: true
);
// With filter and validation
$column = new DataColumn(
property: 'email',
filter: new TextFilterWidget(),
filterValidation: [new EmailValidator()]
);
// With custom content
$column = new DataColumn(
content: fn($model) => Html::encode($model->fullName)
);
// With custom empty value checking
$column = new DataColumn(
property: 'status',
filterEmpty: fn($value) => $value === 0 || $value === null,
);
| public __construct( string|null $property = null, string|null $header = null, boolean $encodeHeader = true, string|null $footer = null, array $columnAttributes = [], array $headerAttributes = [], array|callable $bodyAttributes = [], boolean $withSorting = true, callable|float|integer|string|\Stringable|Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface|null $content = null, boolean|null $encodeContent = null, array|boolean|Yiisoft\Yii\DataView\Filter\Widget\FilterWidget $filter = false, Yiisoft\Yii\DataView\Filter\Factory\FilterFactoryInterface|string|null $filterFactory = null, array|\Yiisoft\Validator\RuleInterface|null $filterValidation = null, boolean|callable|null $filterEmpty = null, boolean $visible = true, string|null $columnClass = null, string|null $headerClass = null, callable|string|string[]|null $bodyClass = null ): mixed | ||
| $property | string|null |
The property name of the data model to be displayed in this column. |
| $header | string|null |
The header cell content. |
| $encodeHeader | boolean |
Whether to HTML-encode the header cell content. |
| $footer | string|null |
The footer cell content. |
| $columnAttributes | array |
HTML attributes for all column cells. |
| $headerAttributes | array |
HTML attributes for the header cell. |
| $bodyAttributes | array|callable |
HTML attributes for the body cells. Can be a callable that returns attributes.
The callable signature is: |
| $withSorting | boolean |
Whether this column is sortable. |
| $content | callable|float|integer|string|\Stringable|Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface|null |
Custom content for data cells.
Can be a callable with signature:
|
| $encodeContent | boolean|null |
Whether to HTML-encode the cell content. Supported values:
|
| $filter | array|boolean|Yiisoft\Yii\DataView\Filter\Widget\FilterWidget |
Filter configuration. Can be:
|
| $filterFactory | Yiisoft\Yii\DataView\Filter\Factory\FilterFactoryInterface|string|null |
Factory for creating filter widgets. |
| $filterValidation | array|\Yiisoft\Validator\RuleInterface|null |
Validation rules for filter values. Can be a single rule or array of rules. |
| $filterEmpty | boolean|callable|null |
Function to determine if a filter value is empty. Can be:
|
| $visible | boolean |
Whether the column is visible. |
| $columnClass | string|null |
Additional CSS class for all column cells. |
| $headerClass | string|null |
Additional CSS class for the header cell. |
| $bodyClass | callable|string|string[]|null |
Additional CSS class for the body cells. |
public function __construct(
public readonly ?string $property = null,
public readonly ?string $header = null,
public readonly bool $encodeHeader = true,
public readonly ?string $footer = null,
public readonly array $columnAttributes = [],
public readonly array $headerAttributes = [],
public readonly mixed $bodyAttributes = [],
public readonly bool $withSorting = true,
string|Stringable|int|float|callable|ValuePresenterInterface|null $content = null,
public readonly ?bool $encodeContent = null,
public readonly bool|array|FilterWidget $filter = false,
public readonly string|FilterFactoryInterface|null $filterFactory = null,
public readonly array|RuleInterface|null $filterValidation = null,
bool|callable|null $filterEmpty = null,
private readonly bool $visible = true,
public readonly ?string $columnClass = null,
public readonly ?string $headerClass = null,
string|array|callable|null $bodyClass = null,
) {
$this->content = $content;
$this->filterEmpty = $filterEmpty;
$this->bodyClass = $bodyClass;
}
| public getRenderer( ): string |
public function getRenderer(): string
{
return DataColumnRenderer::class;
}
Signup or Login in order to comment.