1
votes

In Yii2 for view button in gridview show dropdown i.e view1,view2 etc in dropdown menus

'template' => '{view}',
                'buttons' => [
                    'view' => function ($url, $model) {
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>',Url::to(['order/viewsubscription','id'=>$model->id]), ['title' => 'Update','style'=>'background:none;border:none']); 

                    },

                  ],
2

2 Answers

1
votes

Add dropdown like below:

 [  
        'class' => 'yii\grid\ActionColumn',
        'contentOptions' => ['style' => 'width:260px;'],
        'header'=>'Actions',
        'template' => '{view}',
        'buttons' => [

            //view button
            'view' => function ($url, $model) {

                 return  '<div class="dropdown">
                          <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
                          <span class="caret"></span></button>
                          <ul class="dropdown-menu">
                          <li>'.Html::a('<span class="glyphicon glyphicon-eye-open"></span>',Url::to(['order/viewsubscription','id'=>$model->id]), ['title' => 'Update','style'=>'background:none;border:none']).' </li>
                          <li>'.Html::a('<span class="glyphicon glyphicon-eye-open"></span>',Url::to(['order/viewsubscription','id'=>$model->id]), ['title' => 'Update','style'=>'background:none;border:none']).' </li>
                          </ul>
                        </div>';


            },
        ],

       ],
1
votes

Here is the dropdown menu I am using.

use yii\bootstrap\ButtonDropdown;

[
    'class' => 'yii\grid\ActionColumn',
    'template' => '{view} {update} {more}',
    'buttons' => [
        'more' => function ($url, $model, $key) {
            return ButtonDropdown::widget([
                'label' => Yii::t('app', 'More Actions'),
                'tagName' => 'a',
                'options' => [
                    'class' => 'label label-default'
                ],
                'dropdown' => [
                    'options' => [
                        'class' => ['dropdown-menu-right'],
                    ],
                    'items' => [
                        [
                            'label' => Yii::t('app', 'View Link1'),
                            'url' => [],
                        ],
                        [
                            'label' => Yii::t('app', 'View Link2'),
                            'url' => [],
                        ],
                    ],
                ],
            ]);
        }
    ],
],