Yii Framework Forum: Disable Delete button - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Disable Delete button Disable default delete button Rate Topic: -----

#1 User is offline   khush@l 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 26-March 13

Posted 12 February 2016 - 04:11 AM

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 !!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,523
  • Joined: 12-October 09
  • Location:Croatia

Posted 12 February 2016 - 04:20 AM

Hi... this comment on the CButtonColumn documentation will help you - http://www.yiiframew...tonColumn#c3145
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   khush@l 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 26-March 13

Posted 12 February 2016 - 04:25 AM

View PostMaurizio Domba Cerin, on 12 February 2016 - 04:20 AM, said:

Hi... this comment on the CButtonColumn documentation will help you - http://www.yiiframew...tonColumn#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 :)
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,523
  • Joined: 12-October 09
  • Location:Croatia

Posted 12 February 2016 - 05:20 AM

The only solution I can think of is to use cssClassExpression ( http://www.yiiframew...pression-detail ) and then assign some CSS classes that would disable the delete button
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   khush@l 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 26-March 13

Posted 12 February 2016 - 06:13 AM

View PostMaurizio Domba Cerin, on 12 February 2016 - 05:20 AM, said:

The only solution I can think of is to use cssClassExpression ( http://www.yiiframew...pression-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.
0

#6 User is offline   hrnair 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 231
  • Joined: 09-December 12

Posted 12 February 2016 - 08:43 AM

Could you please share the css you apply to the row
0

#7 User is offline   khush@l 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 26-March 13

Posted 13 February 2016 - 12:09 AM

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()) :

if(isset($button['options']['checkdisable']) && $this->evaluateExpression($button['options']['checkdisable'],array('row'=>$row,'data'=>$data)))
{
$button['options']['disabled'] = true;
unset($button['options']['checkdisable']);
}


Hope it can be usefull for others.
Thank you All for your suggestions.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users