Interface Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface
Interface for column renderers that handle the visual presentation of grid columns.
Column renderers are responsible for transforming column definitions into HTML output by configuring cells for different parts of the column (container, header, body, footer). Each renderer works with a specific column type and handles its unique rendering requirements.
Features:
- Column container configuration
- Header cell rendering with optional visibility
- Data cell rendering with row context
- Footer cell rendering
- Context-aware rendering decisions
Example implementation:
`php
class CustomColumnRenderer implements ColumnRendererInterface
{
public function renderColumn(ColumnInterface $column, Cell $cell, GlobalContext $context): Cell
{
return $cell->addClass('custom-column');
}
public function renderHeader(ColumnInterface $column, Cell $cell, HeaderContext $context): ?Cell
{
return $cell->content('Custom Header');
}
public function renderBody(ColumnInterface $column, Cell $cell, DataContext $context): Cell
{
return $cell->content($context->data['value']);
}
public function renderFooter(ColumnInterface $column, Cell $cell, GlobalContext $context): Cell
{
return $cell->content('Total');
}
}
`
See also:
- Yiisoft\Yii\DataView\GridView\Column\Base\Cell The cell object that gets configured by the renderer.
- Yiisoft\Yii\DataView\GridView\Column\ColumnInterface The column definition interface.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| renderBody() | Configures a data row cell. | Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface |
| renderColumn() | Configures the column container cell. | Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface |
| renderFooter() | Configures the column footer cell. | Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface |
| renderHeader() | Configures the column header cell. | Yiisoft\Yii\DataView\GridView\Column\ColumnRendererInterface |
Method Details
Configures a data row cell.
This method is called for each row in the grid to render the column's data cell.
| public abstract Yiisoft\Yii\DataView\GridView\Column\Base\Cell renderBody ( Yiisoft\Yii\DataView\GridView\Column\ColumnInterface $column, Yiisoft\Yii\DataView\GridView\Column\Base\Cell $cell, Yiisoft\Yii\DataView\GridView\Column\Base\DataContext $context ) | ||
| $column | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
The column definition to render. |
| $cell | Yiisoft\Yii\DataView\GridView\Column\Base\Cell |
The body cell to configure. |
| $context | Yiisoft\Yii\DataView\GridView\Column\Base\DataContext |
Row-specific data and rendering context. |
| return | Yiisoft\Yii\DataView\GridView\Column\Base\Cell |
The configured data cell. |
|---|---|---|
public function renderBody(ColumnInterface $column, Cell $cell, DataContext $context): Cell;
Configures the column container cell.
This method is called once per column to set up the container that will hold all the column's cells.
| public abstract Yiisoft\Yii\DataView\GridView\Column\Base\Cell renderColumn ( Yiisoft\Yii\DataView\GridView\Column\ColumnInterface $column, Yiisoft\Yii\DataView\GridView\Column\Base\Cell $cell, Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext $context ) | ||
| $column | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
The column definition to render. |
| $cell | Yiisoft\Yii\DataView\GridView\Column\Base\Cell |
The cell container to configure. |
| $context | Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext |
Global grid rendering context. |
| return | Yiisoft\Yii\DataView\GridView\Column\Base\Cell |
The configured column container cell. |
|---|---|---|
public function renderColumn(ColumnInterface $column, Cell $cell, GlobalContext $context): Cell;
Configures the column header cell.
| public abstract Yiisoft\Yii\DataView\GridView\Column\Base\Cell|null renderHeader ( Yiisoft\Yii\DataView\GridView\Column\ColumnInterface $column, Yiisoft\Yii\DataView\GridView\Column\Base\Cell $cell, Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext $context ) | ||
| $column | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
The column definition to render. |
| $cell | Yiisoft\Yii\DataView\GridView\Column\Base\Cell |
The header cell to configure. |
| $context | Yiisoft\Yii\DataView\GridView\Column\Base\GlobalContext |
Global grid rendering context. |
| return | Yiisoft\Yii\DataView\GridView\Column\Base\Cell|null |
The configured header cell, or |
|---|---|---|
public function renderHeader(ColumnInterface $column, Cell $cell, GlobalContext $context): ?Cell;
Signup or Login in order to comment.