CButtonColumn - set template under condition

hi there

i have a problem with setting the template property of CButtonColumn

i smth like this

as i saw it in an example in this forum, but i get

i tried it also like this: ( put the condition in single quotes)

but then it always shows me {update} | {delete}, i guess it doesn’t parse the ($data->deactivated_at), but just seet it’s not empty

how should i do this?

thanks :)

There is a visible-property for each button (look here). There you can set a PHP expression which should do the job.

You can’t use an expression for the template property. Instead use the buttons property and define the expression for visible:




'buttons'=>array(

  'delete'=>array(

    'visible'=>'$data->deactivated_at',

  ),

),




You have sintax error in your logic you cant use

‘template’=>empty($data->deactivated_at) ? ‘{update} | {delete}’:’ {update} ',

try

‘template’=>empty($data->deactivated_at) ? ‘{delete}’:’{update}’,

this should solve your issue

It will not, as this expression is only evaluated once, when the data grid is initialized. ggogggo needs an expression that is evaluated for every row (as you can see from his use of the $data object).

Please avoid to post so much source code as this clutters the forum. It’s better to link to the API docs (where you can also expand the source code) or even to the SVN code browser at google code.

yep, that works :)

thanks, Mike

ok thanks, i will post link next time, i apologize for wrong answer

Thanks very much, man, that’s exactly what I was looking for

thanks,

this is what work for me…




 'approve' => array(

                    'label'=>'Approve',

                    'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',                    

                    'options'=>array('style'=>'padding:0 5px 0 0;'),

                    'url'=>'Yii::app()->controller->createUrl("statusapprove",array("id"=>$data->primaryKey))',

                    'visible'=>'($data->requestStatus=="new" || $data->requestStatus=="deny" )?true:false',

                ),