Hide Yii2 GridView Action buttons

后端 未结 10 577
失恋的感觉
失恋的感觉 2021-02-03 21:20

I want to hide Yii2 GridView Action Column buttons on the base of model field status. If status is = 1 then hide view button only. How I can?

Code:

              


        
10条回答
  •  时光说笑
    2021-02-03 21:50

    Use visibleButtons property from ActionColumn class:

    [
        'class' => 'yii\grid\ActionColumn',
        'visibleButtons' => [
            'view' => function ($model, $key, $index) {
                return $model->status !== 1;
             }
        ]
    ]
    

    Reference: https://www.yiiframework.com/doc/api/2.0/yii-grid-actioncolumn#$visibleButtons-detail

提交回复
热议问题