RayShawnOfNapalm
RayShawnOfNapalm

Reputation: 210

Yii2 Framework: Disable certain buttons in GridView widget

I have a GridView made by Gii and I'd like to disable the edit/update button for every item.

Is there any way do this?

Upvotes: 0

Views: 2065

Answers (2)

MoVod
MoVod

Reputation: 1121

You can toggle the visibility of disabled buttons like this:

[
    'headerOptions' => ['width' => '90px'],
    'class' => 'app\components\ActionColumn',
    'template' => '{update} {delete}',
    // display conditional buttons
    'visibleButtons' => [
        'update' => true,
        'delete' => function ($m) { 
            return $m->isDeletable();
        }
    ]
],

Upvotes: 2

Insane Skull
Insane Skull

Reputation: 9368

Use template in Action Column:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        .
        .
        .
        .
        [
         'class' => 'yii\grid\ActionColumn',
        'template' => '{view} {delete}',
       ],
]); ?>

Upvotes: 4

Related Questions