I would like to display action button as dropdown in Yii 2 gridview. How can I achieve that without using any extension?
I have added the source code bellow-
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
['class' => 'yii\grid\ActionColumn',
'template'=>'{view}{update}{delete}',
'buttons' => [
'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),
]);
},
'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Update'),
]);
},
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
$url ='/site/view?id='.$model->id;
return $url;
}
if ($action === 'update') {
$url ='/site/update?id='.$model->id;
return $url;
}
}
],
],
]); ?>
Here is how I did it:
You can check ButtonDropdown documentation here.
Google "Bootstrap Dropdowns" and then replace actions in 'template'=>'{view}{update}{delete}' with what you find. Leaving these three actions instead of text.
Regards.