Disable Delete button

Hello All,

In CGridview, I want to disable “Delete” button for some rows based on condition. I don’t want to hide Delete button. Just want to disable it, so user can view delete button but can not click on that button. If user status is ‘ACTIVE’ at that time only Delete button will be Enable and user can click on it.

Thank in Advance !!

Hi… this comment on the CButtonColumn documentation will help you - http://www.yiiframework.com/doc/api/1.1/CButtonColumn#c3145

I can use ‘Visible’ property but it will hide the button and I don’t want it. If I use ‘htmlOptions’, in that I can not put conditions for each row. Can you please explain in detail or if possible plese give example.

Thank you :)

The only solution I can think of is to use cssClassExpression ( http://www.yiiframework.com/doc/api/1.1/CGridColumn#cssClassExpression-detail ) and then assign some CSS classes that would disable the delete button

Thank you for the Reply, But still I am not getting proper solution. CSS class is applying for entire row, not for a single button or column. If I make it readonly, it will apply to row and whole row is now readonly including update and delete button. As I want to apply CSS only on Delete Button.

Could you please share the css you apply to the row

Found a proper solution to disable a Delete button. I added new attribute as ‘checkDisable’.

With Delete button, I wrote new attribute as :

‘checkdisable’ => '$data->spn_status == Yii::app()->params[“statusInUse”] ', (It must return either true or false)

In framework/zii/widgets/grid/CButtonColumn.php file --> After 342 line put this code (in protected function renderButton()) :

[b]if(isset($button[‘options’][‘checkdisable’]) && $this->evaluateExpression($button[‘options’][‘checkdisable’],array(‘row’=>$row,‘data’=>$data)))

{

$button[‘options’][‘disabled’] = true;

unset($button[‘options’][‘checkdisable’]);

}[/b]

Hope it can be usefull for others.

Thank you All for your suggestions.