CButtonColumn
CButtonColumn represents a grid view column that renders one or several buttons.
By default, it will display three buttons, "view", "update" and "delete", which triggers the corresponding
actions on the model of the row.
By configuring
buttons and
template properties, the column can display other buttons
and customize the display order of the buttons.
Public Properties
Hide inherited properties
| Property | Type | Description | Defined By |
| buttons |
array |
the configuration for additional buttons. |
CButtonColumn |
| cssClassExpression |
string |
a PHP expression that is evaluated for every data cell and whose result
is used as the CSS class name for the data cell. |
CGridColumn |
| deleteButtonImageUrl |
string |
the image URL for the delete button. |
CButtonColumn |
| deleteButtonLabel |
string |
the label for the delete button. |
CButtonColumn |
| deleteButtonOptions |
array |
the HTML options for the view button tag. |
CButtonColumn |
| deleteButtonUrl |
string |
a PHP expression that is evaluated for every delete button and whose result is used
as the URL for the delete button. |
CButtonColumn |
| deleteConfirmation |
string |
the confirmation message to be displayed when delete button is clicked. |
CButtonColumn |
| grid |
CGridView |
the grid view object that owns this column. |
CGridColumn |
| htmlOptions |
array |
the HTML options for the data cell tags. |
CGridColumn |
| id |
string |
the ID of this column. |
CGridColumn |
| template |
string |
the template that is used to render the content in each data cell. |
CButtonColumn |
| updateButtonImageUrl |
string |
the image URL for the update button. |
CButtonColumn |
| updateButtonLabel |
string |
the label for the update button. |
CButtonColumn |
| updateButtonOptions |
array |
the HTML options for the update button tag. |
CButtonColumn |
| updateButtonUrl |
string |
a PHP expression that is evaluated for every update button and whose result is used
as the URL for the update button. |
CButtonColumn |
| viewButtonImageUrl |
string |
the image URL for the view button. |
CButtonColumn |
| viewButtonLabel |
string |
the label for the view button. |
CButtonColumn |
| viewButtonOptions |
array |
the HTML options for the view button tag. |
CButtonColumn |
| viewButtonUrl |
string |
a PHP expression that is evaluated for every view button and whose result is used
as the URL for the view button. |
CButtonColumn |
| visible |
boolean |
whether this column is visible. |
CGridColumn |
Property Details
public array $buttons;
the configuration for additional buttons. Each array element specifies a single button
which has the following format:
'buttonID' => array(
'label'=>'...', // text label of the button
'url'=>'...', // a PHP expression for generating the URL of the button
'imageUrl'=>'...', // image URL of the button. If not set or false, a text link is used
'options'=>array(...), // HTML options for the button tag
'click'=>'...', // a JS function to be invoked when the button is clicked
'visible'=>'...', // a PHP expression for determining whether the button is visible
)
In the PHP expression for the 'url' option and/or 'visible' option, the variable
$row
refers to the current row number (zero-based), and
$data refers to the data model for
the row.
Note that in order to display these additional buttons, the
template property needs to
be configured so that the corresponding button IDs appear as tokens in the template.
public string $deleteButtonImageUrl;
the image URL for the delete button. If not set, an integrated image will be used.
You may set this property to be false to render a text link instead.
public string $deleteButtonLabel;
the label for the delete button. Defaults to "Delete".
Note that the label will not be HTML-encoded when rendering.
public array $deleteButtonOptions;
the HTML options for the view button tag.
public string $deleteButtonUrl;
a PHP expression that is evaluated for every delete button and whose result is used
as the URL for the delete button. In this expression, the variable
$row the row number (zero-based); $data the data model for the row;
and $this the column object.
public string $deleteConfirmation;
the confirmation message to be displayed when delete button is clicked.
By setting this property to be false, no confirmation message will be displayed.
public string $template;
the template that is used to render the content in each data cell.
These default tokens are recognized: {view}, {update} and {delete}. If the buttons property
defines additional buttons, their IDs are also recognized here. For example, if a button named 'preview'
is declared in buttons, we can use the token '{preview}' here to specify where to display the button.
public string $updateButtonImageUrl;
the image URL for the update button. If not set, an integrated image will be used.
You may set this property to be false to render a text link instead.
public string $updateButtonLabel;
the label for the update button. Defaults to "Update".
Note that the label will not be HTML-encoded when rendering.
public array $updateButtonOptions;
the HTML options for the update button tag.
public string $updateButtonUrl;
a PHP expression that is evaluated for every update button and whose result is used
as the URL for the update button. In this expression, the variable
$row the row number (zero-based); $data the data model for the row;
and $this the column object.
public string $viewButtonImageUrl;
the image URL for the view button. If not set, an integrated image will be used.
You may set this property to be false to render a text link instead.
public string $viewButtonLabel;
the label for the view button. Defaults to "View".
Note that the label will not be HTML-encoded when rendering.
public array $viewButtonOptions;
the HTML options for the view button tag.
public string $viewButtonUrl;
a PHP expression that is evaluated for every view button and whose result is used
as the URL for the view button. In this expression, the variable
$row the row number (zero-based); $data the data model for the row;
and $this the column object.
Method Details
Initializes the column.
This method registers necessary client script for the button column.
|
protected void initDefaultButtons()
|
Initializes the default buttons (view, update and delete).
|
protected void registerClientScript()
|
Registers the client scripts for the button column.
|
protected void renderButton(string $id, array $button, integer $row, mixed $data)
|
| $id |
string |
the ID of the button |
| $button |
array |
the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
See buttons for more details. |
| $row |
integer |
the row number (zero-based) |
| $data |
mixed |
the data object associated with the row |
Renders a link button.
|
protected void renderDataCellContent(integer $row, mixed $data)
|
| $row |
integer |
the row number (zero-based) |
| $data |
mixed |
the data associated with the row |
Renders the data cell content.
This method renders the view, update and delete buttons in the data cell.
Since an example is worth a thousand words, here's how to set the url for CButtonColumn buttons: