Final Class Yiisoft\Yii\DataView\GridView\Column\ActionColumn
| Inheritance | Yiisoft\Yii\DataView\GridView\Column\ActionColumn |
|---|---|
| Implements | Yiisoft\Yii\DataView\GridView\Column\ColumnInterface |
ActionColumn is a column for the {@see GridView} widget that displays buttons for viewing and manipulating
the items.
// Basic usage with default view, update, and delete buttons
$column = new ActionColumn();
// Custom URL creator
$column = new ActionColumn(
urlCreator: static fn(string $action, DataContext $context): string => "/$action/{$context->data->id},
);
// Custom buttons using ActionButton instances
$column = new ActionColumn(
buttons: [
'view' => new ActionButton(
content: '🔎',
url: static fn(array|object $data, DataContext $context): string => "/view/$data->id",
title: 'View',
),
'delete' => new ActionButton(
content: '❌',
url: static fn(array|object $data, DataContext $context): string => "/delete/$data->id",
title: 'Delete',
attributes: ['onclick' => "return confirm('Are you sure?')"],
),
],
);
// Custom buttons using callables
$column = new ActionColumn(
buttons: [
'approve' => static fn(string $url): string => Html::a('Approve', $url, ['class' => 'btn btn-success']),
],
template: '{approve}',
);
// Conditionally visible buttons
$column = new ActionColumn(
visibleButtons: [
'delete' => static fn(array|object $data, DataContext $context): bool => $data['deletable'],
],
);
Public Properties
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\DataView\GridView\Column\ActionColumn | |
| getRenderer() | Yiisoft\Yii\DataView\GridView\Column\ActionColumn | |
| getUrlCreator() | Get the URL creator callback. | Yiisoft\Yii\DataView\GridView\Column\ActionColumn |
| isVisible() | Yiisoft\Yii\DataView\GridView\Column\ActionColumn |
Property Details
Method Details
| public mixed __construct ( string|null $template = null, string|null $before = null, string|null $after = null, mixed $urlConfig = null, callable|null $urlCreator = null, string|null $header = null, string|null $footer = null, mixed $content = null, array|null $buttons = null, array|null $visibleButtons = null, array $columnAttributes = [], array $headerAttributes = [], array $bodyAttributes = [], array $footerAttributes = [], boolean $visible = true ) | ||
| $template | string|null |
The template used for composing each cell in the action column. |
| $before | string|null |
Content to be prepended to the action column content. |
| $after | string|null |
Content to be appended to the action column content. |
| $urlConfig | mixed |
URL configuration for generating button URLs. |
| $urlCreator | callable|null |
A callback that creates a button URL using the specified data information. |
| $header | string|null |
The header cell content. |
| $footer | string|null |
The footer cell content. |
| $content | mixed |
The content to be rendered in each data cell. |
| $buttons | array|null |
Array of buttons. Keys are button names. Values are either instances
of {@see \Yiisoft\Yii\DataView\GridView\Column\ActionButton} or a callable with the following signature:
|
| $visibleButtons | array|null |
Array of button visibility rules. |
| $columnAttributes | array |
HTML attributes for the column cells. |
| $headerAttributes | array |
HTML attributes for the header cell. |
| $bodyAttributes | array |
HTML attributes for the body cells. |
| $footerAttributes | array |
HTML attributes for the footer cell. |
| $visible | boolean |
Whether the column is visible. |
public function __construct(
public readonly ?string $template = null,
public readonly ?string $before = null,
public readonly ?string $after = null,
public readonly mixed $urlConfig = null,
?callable $urlCreator = null,
public readonly ?string $header = null,
public readonly ?string $footer = null,
public readonly mixed $content = null,
public readonly ?array $buttons = null,
public readonly ?array $visibleButtons = null,
public readonly array $columnAttributes = [],
public readonly array $headerAttributes = [],
public readonly array $bodyAttributes = [],
public readonly array $footerAttributes = [],
private readonly bool $visible = true,
) {
$this->urlCreator = $urlCreator;
}
| public string getRenderer ( ) |
public function getRenderer(): string
{
return ActionColumnRenderer::class;
}
Get the URL creator callback.
| public callable|null getUrlCreator ( ) | ||
| return | callable|null |
The URL creator callback. |
|---|---|---|
public function getUrlCreator(): ?callable
{
return $this->urlCreator;
}
Signup or Login in order to comment.