0 follower

Final Class Yiisoft\Yii\DataView\GridView\Column\DataColumn

InheritanceYiisoft\Yii\DataView\GridView\Column\DataColumn
ImplementsYiisoft\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

Hide inherited properties

Property Type Description Defined By
$bodyAttributes mixed Yiisoft\Yii\DataView\GridView\Column\DataColumn
$bodyClass callable|string|string[]|null Additional CSS class for the body cells. Yiisoft\Yii\DataView\GridView\Column\DataColumn
$columnAttributes array Yiisoft\Yii\DataView\GridView\Column\DataColumn
$columnClass string|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$content callable|float|integer|string|\Stringable|Yiisoft\Yii\DataView\ValuePresenter\ValuePresenterInterface|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$encodeContent boolean|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$encodeHeader boolean Yiisoft\Yii\DataView\GridView\Column\DataColumn
$filter boolean|array|Yiisoft\Yii\DataView\Filter\Widget\FilterWidget Yiisoft\Yii\DataView\GridView\Column\DataColumn
$filterEmpty boolean|callable|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$filterFactory string|Yiisoft\Yii\DataView\Filter\Factory\FilterFactoryInterface|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$filterValidation array|\Yiisoft\Validator\RuleInterface|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$footer string|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$header string|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$headerAttributes array Yiisoft\Yii\DataView\GridView\Column\DataColumn
$headerClass string|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$property string|null Yiisoft\Yii\DataView\GridView\Column\DataColumn
$withSorting boolean Yiisoft\Yii\DataView\GridView\Column\DataColumn

Property Details

Hide inherited properties

$bodyAttributes public property
public mixed $bodyAttributes = []
$bodyClass public property

Additional CSS class for the body cells.

$columnAttributes public property
$columnClass public property
public string|null $columnClass null
$encodeContent public property
public boolean|null $encodeContent null
$encodeHeader public property
public boolean $encodeHeader true
$filter public property
$filterEmpty public property
$filterValidation public property
public array|\Yiisoft\Validator\RuleInterface|null $filterValidation null
$footer public property
public string|null $footer null
$header public property
public string|null $header null
$headerAttributes public property
$headerClass public property
public string|null $headerClass null
$property public property
public string|null $property null
$withSorting public property
public boolean $withSorting true

Method Details

Hide inherited methods

__construct() public method

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: function(array|object $data, DataContext $context): array.

$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: function(array|object $data, DataContext $context): string|Stringable|int|float.

$encodeContent boolean|null

Whether to HTML-encode the cell content. Supported values:

  • null: stringable objects implementing \Yiisoft\Yii\DataView\GridView\Column\NoEncodeStringableInterface aren't encoded, everything else is encoded (default behavior);
  • true: any content is encoded, regardless of type;
  • false: nothing is encoded, use with caution and only for trusted content.
$filter array|boolean|Yiisoft\Yii\DataView\Filter\Widget\FilterWidget

Filter configuration. Can be:

  • false (disabled)
  • array (filter options)
  • FilterWidget instance (custom filter widget)
$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:

  • null: Uses default empty value checking (empty() function)
  • true: Always considers the value empty (disables filtering)
  • false: Always considers the value non-empty (enables filtering)
  • callable: Custom function to determine emptiness with signature:
    function (mixed $value): bool {
        // Return true if value should be considered empty
        return $value === '' || $value === null;
    }
    
$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;
}

            
getRenderer() public method

public getRenderer( ): string

                public function getRenderer(): string
{
    return DataColumnRenderer::class;
}

            
isVisible() public method

public isVisible( ): boolean

                public function isVisible(): bool
{
    return $this->visible;
}