Update – Delete – View
I’m sure you’ve already seen and used the basic buttons in a CGridView and maybe even used the template phrases to modify the behaviours
| PHP | | copy code | | ? |
| 01 | array( |
| 02 | 'class'=>'CButtonColumn', |
| 03 | 'template'=>'{delete}{update}', |
| 04 | 'buttons'=>array( |
| 05 | 'update'=>array( |
| 06 | 'url'=>'$this->grid->controller->createUrl("/History/update", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))', |
| 07 | 'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open"); return false;}', |
| 08 | ), |
| 09 | 'delete'=>array( |
| 10 | 'url'=>'$this->grid->controller->createUrl("/History/delete", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))', |
| 11 | ), |
| 12 | ), |
but sometimes we need to break out of this box and create custom buttons for slightly more exciting function like ordering with up and down buttons, or email, or add … and many more!
Custom Buttons
So you can add custom templates (or re-define existing ones) by using further properties of the CButtonColumn object as follows:-
| PHP | | copy code | | ? |
| 01 | array( |
| 02 | 'class'=>'CButtonColumn', |
| 03 | 'template'=>'{update}{add}{delete}', |
| 04 | 'buttons'=>array( |
| 05 | 'update'=>array( |
| 06 | 'url'=>'$this->grid->controller->createUrl("/Extras/update", array("id"=>$data->id,"asDialog"=>1,"gridId"=>$this->grid->id))', |
| 07 | 'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open"); return false;}', |
| 08 | 'visible'=>'($data->id===null)?false:true;' |
| 09 | ), |
| 10 | 'add' => array( |
| 11 | 'label'=>'Add', |
| 12 | 'imageUrl'=>Yii::app()->request->baseUrl.'/css/gridViewStyle/images/gr-plus.png', |
| 13 | 'url'=>'$this->grid->controller->createUrl("/Extras/create", array("eid"=>$data->extras_id, "bid"=>'.$model->id.', "asDialog"=>1,"gridId"=>$this->grid->id))', |
| 14 | 'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open"); return false;}', |
| 15 | 'visible'=>'($data->id===null)?true:false;' |
| 16 | ), |
| 17 | 'delete'=>array( |
| 18 | 'url'=>'$this->grid->controller->createUrl("/Extras/delete", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))', |
| 19 | ), |
| 20 | |
| 21 | ), |
| 22 | ), |
Let’s have closer look at how this works …
Blog
Photography
Yii Framework
My Portfolio