This code shows about how to add a custom button with your own icon for your CGridView of Yii framework.“view”, “update”, “delete” button and it have corresponding actions. We can change it using CButtonColumn properties.
widget('zii.widgets.grid.CGridView', array( 'id'=>'modelname-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'rowname1', 'rowname2', array( 'class'=>'CButtonColumn', 'template'=>'{view}{update}{delete}', 'deleteButtonImageUrl' => Yii::app()->theme->baseUrl .'/images/'.'close-button.png', 'deleteButtonOptions'=>array( 'class'=>'delete_class', 'id'=>'delete_id', ), 'updateButtonImageUrl' => Yii::app()->theme->baseUrl .'/images/'.'edit-button.png', 'updateButtonOptions'=>array( 'class'=>'update_class', 'id'=>'update_id', ), 'viewButtonImageUrl' => Yii::app()->theme->baseUrl .'/images/'.'view-button.png', 'viewButtonOptions'=>array( 'class'=>'view_class', 'id'=>'view_id', ), ), ), )); ?>
if you want add this in YII framework follow this
open \CButtonColumn.php
..\yii\framework\zii\widgets\grid\CButtonColumn.php
defult code[line 215] function initDefaultButtons()
protected function initDefaultButtons() { if($this->viewButtonLabel===null) $this->viewButtonLabel=Yii::t('zii','View'); if($this->updateButtonLabel===null) $this->updateButtonLabel=Yii::t('zii','Update'); if($this->deleteButtonLabel===null) $this->deleteButtonLabel=Yii::t('zii','Delete'); if($this->viewButtonImageUrl===null) $this->viewButtonImageUrl=$this->grid->baseScriptUrl.'/view.png'; if($this->updateButtonImageUrl===null) $this->updateButtonImageUrl=$this->grid->baseScriptUrl.'/update.png'; if($this->deleteButtonImageUrl===null) $this->deleteButtonImageUrl=$this->grid->baseScriptUrl.'/delete.png'; }
update code function initDefaultButtons()
protected function initDefaultButtons() { if($this->viewButtonLabel===null) $this->viewButtonLabel=Yii::t('zii','View'); if($this->updateButtonLabel===null) $this->updateButtonLabel=Yii::t('zii','Update'); if($this->deleteButtonLabel===null) $this->deleteButtonLabel=Yii::t('zii','Delete'); if($this->viewButtonImageUrl===null) $this->viewButtonImageUrl=Yii::app()->theme->baseUrl .'/images/'.'view-button.png'; if($this->updateButtonImageUrl===null) $this->updateButtonImageUrl=Yii::app()->theme->baseUrl .'/images/'.'edit-button.png'; if($this->deleteButtonImageUrl===null) $this->deleteButtonImageUrl=Yii::app()->theme->baseUrl .'/images/'.'close-button.png'; }
0 comments:
Post a Comment