简体   繁体   中英

Is possible to disable update button from CButtonColumn for first two values in Yii

In my Yii web application, I want to disable update link for first two values in CButtonColumn. How to resolve this. My Cgridview is, 在此处输入图片说明

Please help me.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM