I have CButtonColumn in CGridView:
array(
'class' => 'CButtonColumn',
'template'=>'{document}',
'buttons'=>array(
'document'=>array(
'imageUrl'=>'icon.gif',
'url' => '($data->status=="1") ? Yii::app()->createUrl("site/getDocument") : "" ',
'click' => 'js:function() { alert("There isn't file");}'
),
),
),
But I want open will be opening alert only when $data->status=="1", but I can't insert php code in 'click'. So There is any possibility to do this?
From http://www.yiiframework.com/doc/api/1.1/CButtonColumn:
'buttonID' => array(
'label'=>'...', // text label of the button
'url'=>'...', // a PHP expression for generating the URL of the button
'imageUrl'=>'...', // image URL of the button. If not set or false, a text link is used
'options'=>array(...), // HTML options for the button tag
'click'=>'...', // a JS function to be invoked when the button is clicked
'visible'=>'...', // a PHP expression for determining whether the button is visible
)
"In the PHP expression for the 'url' option and/or 'visible' option, the variable $row refers to the current row number (zero-based), and $data refers to the data model for the row. A PHP expression can be any PHP code that has a value." You can access elements on DOM to get the values you want.
You can try this:
array(
'class' => 'CButtonColumn',
'template'=>'{document}',
'buttons'=>array(
'document'=>array(
'imageUrl'=>'icon.gif',
'url' => '($data->status=="1") ? Yii::app()->createUrl("site/getDocument") : "" ',
'click' => 'function() { if($(this).attr("href") !== "") alert("There isn't file");}',
),
),
),