Class yeesoft\grid\columns\TitleActionColumn

Inheritanceyeesoft\grid\columns\TitleActionColumn » yii\grid\DataColumn

TitleActionColumn is a column for the \yeesoft\grid\columns\GridView widget that displays action buttons and title for viewing and manipulating the items.

To add an TitleActionColumn to the gridview, add it to the \yeesoft\grid\columns\GridView::columns configuration as follows:

'columns' => [
    // ...
    [
        'class' => TitleActionColumn::className(),
        // you may configure additional properties here
    ],
]

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attribute yeesoft\grid\columns\TitleActionColumn
$buttonOptions array Html options to be applied to the default buttons. yeesoft\grid\columns\TitleActionColumn
$buttons array Button rendering callbacks. yeesoft\grid\columns\TitleActionColumn
$buttonsTemplate yeesoft\grid\columns\TitleActionColumn
$controller string The ID of the controller that should handle the actions specified here. yeesoft\grid\columns\TitleActionColumn
$template string The template used for composing each cell in the action column. yeesoft\grid\columns\TitleActionColumn
$title callable Or string yeesoft\grid\columns\TitleActionColumn
$urlCreator callable A callback that creates a button URL using the specified model information. yeesoft\grid\columns\TitleActionColumn

Public Methods

Hide inherited methods

MethodDescriptionDefined By
createUrl() Creates a URL for the given action and model. yeesoft\grid\columns\TitleActionColumn
init() yeesoft\grid\columns\TitleActionColumn

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
initDefaultButtons() Initializes the default button rendering callbacks. yeesoft\grid\columns\TitleActionColumn
renderDataCellContent() yeesoft\grid\columns\TitleActionColumn
renderFilterCellContent() Renders the filter cell content. yeesoft\grid\columns\TitleActionColumn

Property Details

$attribute public property
public $attribute 'title'
$buttonOptions public property

Html options to be applied to the default buttons.

public array $buttonOptions = []
$buttons public property

Button rendering callbacks. The array keys are the button names (without curly brackets), and the values are the corresponding button rendering callbacks. The callbacks should use the following signature:

function ($url, $model, $key) {
    // return the button HTML code
}

where $url is the URL that the column creates for the button, $model is the model object being rendered for the current row, and $key is the key of the model in the data provider array.

You can add further conditions to the button, for example only display it, when the model is editable (here assuming you have a status field that indicates that):

[
    'update' => function ($url, $model, $key) {
        return $model->status === 'editable' ? Html::a('Update', $url) : '';
    };
],
public array $buttons = []
$buttonsTemplate public property
public $buttonsTemplate '{update} {view} {delete}'
$controller public property

The ID of the controller that should handle the actions specified here. If not set, it will use the currently active controller. This property is mainly used by $urlCreator to create URLs for different actions. The value of this property will be prefixed to each action name to form the route of the action.

public string $controller null
$template public property

The template used for composing each cell in the action column. Tokens enclosed within curly brackets are treated as controller action IDs (also called button names in the context of action column). They will be replaced by the corresponding button rendering callbacks specified in $buttons. For example, the token {view} will be replaced by the result of the callback buttons['view']. If a callback cannot be found, the token will be replaced with an empty string.

As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows:

['class' => 'backend\components\TitleActionColumn', 'template' => '{view} {update}'],

See also $buttons.

public string $template '<span class="action-title">{title}</span> <div class="quick-actions"> {buttons} </div>'
$title public property

Or string

public callable $title null
$urlCreator public property

A callback that creates a button URL using the specified model information. The signature of the callback should be the same as that of createUrl(). If this property is not set, button URLs will be created using createUrl().

public callable $urlCreator null

Method Details

createUrl() public method

Creates a URL for the given action and model.

This method is called for each button and each row.

public string createUrl ( $action, $model, $key, $index )
$action string

The button name (or action ID)

$model yeesoft\db\ActiveRecord

The data model

$key mixed

The key associated with the data model

$index integer

The current row index

return string

The created URL

init() public method

public void init ( )
initDefaultButtons() protected method

Initializes the default button rendering callbacks.

protected void initDefaultButtons ( )
renderDataCellContent() protected method

protected void renderDataCellContent ( $model, $key, $index )
$model
$key
$index
renderFilterCellContent() protected method

Renders the filter cell content.

The default implementation simply renders a space. This method may be overridden to customize the rendering of the filter cell (if any).

protected string renderFilterCellContent ( )
return string

The rendering result