Hide Yii2 GridView Action buttons

后端 未结 10 588
失恋的感觉
失恋的感觉 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:29

    this one worked for me . complete ActionColumn code

    [  
                    'class' => 'yii\grid\ActionColumn',
                    'contentOptions' => ['style' => 'width:260px;'],
                    'header'=>'Actions',
                    'template' => '{view}',
                    'buttons' => [
    
                        //view button
                        'view' => function ($url, $model) {
                            return  Html::a('View', $url, 
    [ 'title' => Yii::t('app', 'View'), 'class'=>'btn btn-primary btn-xs', ]) ;
                        },
                    ],
    
                    'urlCreator' => function ($action, $model, $key, $index) {
                        if ($action === 'view') {
                            $url = \yii\helpers\Url::toRoute(['general-info/viewalldetails', 'id' => $key]);
                            return $url;
                    }
                    }
    ],
    

提交回复
热议问题