Advanced customization of CButtonColumn in CGridView

Hi,

I want to customize CGridView to show my new button in the last column instead of 3 default buttons.

So I created a new file C[color="#800080"]MyCustom[/color]Button.php inside the folder zii/widgets/grid/

And add the line Yii::import(‘zii.widgets.grid.C[color="#800080"]MyCustom[/color]Button’); in CGridView.php

I removed {view}, {update} and {delete} and added a new {mycustomupdate}

Since I havent defined {@link mycustomupdate} property I can see the text {mycustomupdate} in the GridView.

Upto here its fine.

My Question is.

  1. Now where should I define this {@link mycustomupdate} property ? Which file & function ?

  2. I want {mycustomupdate} button to perform 3 actions onclick.

---- to update a related table (if a simple query exec is possible its fine, UPDATE SET blah,blah WHERE id = $data[id])

---- and then sends a email

---- then reloads the same view again. (ajax/non-ajax)

(3 actions in sequence.)

Can anyone give me the outline of how to do this ? (along with filename & function name as well)

I already read this wiki.

http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/

(Only thing I dont get from this tutorial is where to add this new button definition, i.e, which function in CButtonColumn.php, though I understand that array must be added to the $this->buttons array variable. )

The cookbook you referenced… explains how to make new buttons without extending the CButtonColum that you have done…

If you extend a class… instead of changing the framework code… it’s always better to put the extended class in your application path… protected/components or protected/extensions…

If you extend CButtonColumn… you define the class as




		array(

			'class'=>'CMyCustomButton',

		),



but for the beginning (until you get an idea of how to extend a class… follow the cookbook word by word… until you get it working that way, IMHO

hi, thanks for the reply.

Yes, I didn’t want to modify the framework code as in cookbook.(Because I need original version in many other grids)

Instead of extending class by putting file in protected/components or protected/extensions

Ive directly added my class file in zii/widgets/grid folder.

I will try to move into protected/extensions folder.

The most confortable place for extend class is to place the extended class directly in components.

The class in compoments are already included, so you don’t have to change any config.

Once that the class is ready and tested, you can move in extension and include the class using config/main.

Is always better to leave untouched the framework dir, that allow you to update the framework in a safe way.