Yii add new action button to CGridView

In admin grid listing of any controller, we can add a custom action button along with viiew, update and delete.follow the steps:

1. open admin file where your cgridview code is written.
2. edit array(
‘class’=>’CButtonColumn’,
),
to

array
(
‘class’=>’CButtonColumn’,
‘template’=>'{view}{update}{delete}{setattributes}’,
‘buttons’=>array
(
‘setattributes’ => array
(
‘url’=>’Yii::app()->createUrl(“categories/setAttributes”, array(“id”=>$data->id))’,
),
),
),

Params for new button  are:

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.
    '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.
)

 

contact us