I was trying to open Create, View and Update page in Bootstrap 4 modal in GridView. I can do that in Bootstrap 3 but the code doesn’t work for Yii2 Bootstrap 4. Anyone please help how can I open Create, View and Update page in Bootstrap 4 modal in GridView. Recently I’ve upgraded the framework to Bootstrap4. Here is my code:
-
web/js/main.js: $(function(){ $('.custom_button').click(function(){ $('#modalView').modal('show').find('#modalContentView').load($(this).attr('value')); }); });
-
views/branches/index.php: <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], // 'branch_id', 'companies_company_id', 'branch_name', 'branch_address', 'branch_created_date', //'branch_status', // ['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn', 'contentOptions' => ['style' => 'width: 8.7%'], 'visible'=> Yii::$app->user->isGuest ? false : true, 'buttons'=>[ 'view'=>function ($url, $model, $key) { $t = 'index.php?r=branches/view&id='.$key; return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value'=>Url::to($t), 'class' => 'btn btn-default btn-xs custom_button']); }, 'update'=>function ($url, $model, $key) { $t = 'index.php?r=branches/update&id='.$key; return Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value'=>Url::to($t), 'class' => 'btn btn-default btn-xs custom_button']); }, ], ], ], ]); ?> <?php Modal::begin(['id'=>'modalView', 'size'=>'modal-md']); echo "<div id='modalContentView'></div>"; Modal::end(); ?>