Zii Grid View Action Customization

Hello

I am using zii grid view, i change action buttons and they are working fine, using this link Click Here

But i have to add button customization in every controller, Is there any other way by that i can manage it via one file? means i dont want to add same code on every page.

Thanks in advance

Hi Alnakar

One of the way is to extend the zii


Yii::import('zii.widgets.grid.CGridView');


class MyGridView extends CGridView

{

//override the appropriate methods, may call the parent::theMethod()

}

and use ext.yourgridview.yourFilegridview instead of zii.widgets.grid.CGridView

Another way is to create a method in components/conroller.php with argument an array parameters (the parameters of CGridView) merge this array with your custom button and call by itself the CGridView

Thanks KonApaz

Can you provide me some example code.

for gridview you have to extend CButtonColumn in components




Yii::import('zii.widgets.grid.CButtonColumn');


class BButtonColumn extends CButtonColumn{

 public  function initDefaultButtons(){

    // make ur changes here 

  }

}



then use BButtonColumn in ur gridview instead of CButtonColumn

forget the first way I said.

by the second way

In the components/controller just add this code


public function myGridview($arrParams) {


$default = array(

'columns'=>array(

array(

'class'=>'yourCButtonColumn',        

),

),

);


$finalArr = array_merge_recursive($arrParams,$default)

 $this->widget('zii.widgets.grid.CGridView', $finalArr);

}

Make the yourCButtonColumn as Lal Zada post

and in view file call the above function like


$this->myGridview(array( 

'id'=>'an_id',

'dataProvider'=>$model->search(),

'filter'=>$model,

'columns'=>array(

		'id',

		'text',

		'title',

		'and_so_on',

)

));

with this, you minimize the code by add only no-default attributes, I didn’t checked the code so test by yourself and tell us if it works! :)

Thanks

Hi Konapaz

http://www.yiiframework.com/forum/index.php/topic/41661-password-encryption/page__p__198465__fromsearch__1#entry198465

Can you reply on this issue also.