How can i create visible or not a button in che CButtonColumn???

I want that it is visible in same case and invisible in the other case…is possible????

Can you help me???

I would try with

'template' => $some_condition ? '{one} {two}' : '{one} {two} {three}',


'template' => '{one} {two}'.$some_condition' ? ' {three}' : '',

(just a matter of taste)



The example helps when you have an external data to make the condition and for whole grid.

There is a possibility to use data from the current row, a different template regarding the condition? (a status, or a value, or…) like "$data->value==1"?

Or I have to make my own CButtonColumn?

Thank you,


There is a "visible" property for the butons… check the documentation - http://www.yiiframework.com/doc/api/CButtonColumn#buttons-detail


but this works only for all the buttons together or for the additional buttons but not for the default ones, right?

Also I saw that you can for example set the “viewButtonOptions” but these are HTML options and not the options you can set for the “buttons” property so you can’t do that if I’m right:


while it would be useful so you could override the default url and even set the “click” property if you wish without having to create custom additional buttons and set a template ::)

What do you think? Am I right? Thanks.




I’ve found that you can override the click property doing like this:




		'update'=>array('click'=>'js:function (e) { e.preventDefault(); alert("update!"); }'),

		'delete'=>array('click'=>'js:function (e) { e.preventDefault(); alert("delete!"); }'),



	'template'=>'{update} {delete}',


but doesn’t works for the delete one cause the click property is being overwritten in a second time…



As far as I know, visible and all other properties of buttons property works for all buttons, both build-in ones and customized by user.

Look into my cookbook article, maybe it will be some help for you in this matter?


thanks for your reply.

It worked for the update button but not for the delete button; but for the delete button I then just changed the url of the ajax call and this was enough for me ;)