1

In my Yii web application, I want to disable update link for first two values in CButtonColumn. How to resolve this. My Cgridview is, enter image description here

Please help me.

Arya
  • 504
  • 2
  • 8
  • 31
  • do you mean the disabling the `CButtonColumn` buttons for the first two rows in a `CGridView`? – morcen Jun 07 '16 at 05:36
  • yes. I want to disable edit button for the first two rows in CGridView – Arya Jun 07 '16 at 05:39
  • how about after filtering the `CGridView`, or if the grid is in page 2, should the buttons of the first two rows of the resulting data be still disabled? – morcen Jun 07 '16 at 05:41
  • @Jencen, Actually, in my cgridview having five rows only. In that first two rows are predefined, So I want to disable edit button for that two entries and remaining three entries should make editable. How to possible that. – Arya Jun 07 '16 at 05:47

2 Answers2

3

Alright, You can use "visible" attribute for this button in your CButtonColumn and pass a PHP expression (within single quotes) to control when it gets shown and when it doesn't:

For example, the object having attribute "name" equal to "Full-Time Contract" not be shown.

array(
    'class'=>'CButtonColumn',
    'template'=>'{update} {view}',
    'buttons'=>array(
           'update'=>array(
                    'visible'=>'($data->name !== "Full-Time Contract")'
            ),
     ),
)

You can adapt it according to your needs.

Asfandyar Khan
  • 1,677
  • 15
  • 34
2

So you can use Asfi's answer, which is Yii's way to solve this. But if you want something more simple and more general in disabling the first two rows of the table, whatever the values are, then I suggest just do it via jQuery, which is by default supported by Yii.

$('table tr:first-child button,table tr:eq(2) button').prop('disabled',true);

https://jsfiddle.net/ncnm1jme/

morcen
  • 368
  • 2
  • 14