在yii2的网格视图中弹出模式 [英] Modal pop up in grid view in yii2
本文介绍了在yii2的网格视图中弹出模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想弹出一个模式,当我点击网格视图内的按钮时。这可能与yii2 gridview?
<?= GridView :: widget([
'dataProvider'=> ; $ dataProvider,
'filterModel'=> $ searchModel,
'columns'=> [
['class'=>'yii\grid\SerialColumn'],
'time_zone',
'no_of_users',
'bill_name',
'bill_address',
'names.name',
'bill_state',
'bill_city',
'bill_postal',
'bill_mobile',
['header'=&';'计划信息',
'value'=>函数($ data)
{
//〜print_r($ data); die();
return Html :: a(Yii :: t('app','{modelClass}',[
'modelClass'=>'details',
]),['userdetails / plans','id'=> $ data-> id],['class'=>'btn btn-success']
);
},
'format'=> 'raw'
],
['class'=> 'yii\grid\ActionColumn'],
],
]); ?>
在上面的网格视图中我想要一个模式来弹出,当我点击按钮的'细节'。
谢谢,
解决方案
是的,这是可能的。
添加 Modal
上面的代码 GridView $ c
<?php
yii\bootstrap\Modal :: begin(['c' id'=>'modal']);
yii\bootstrap\Modal :: end();
?>
之后,在详情按钮中添加 id
。
Like as,
[
'header'=>'计划信息',
'值'=>函数($ data)
{
return Html :: a(Yii :: t('app','{modelClass}',[
'modelClass'=>'details',
]),['userdetails / plans','id'=> $ data-> id],['class'=>'btn btn-success','id'=>'popupModal ]);
},
'format'=> 'raw'
],
而不是在页面顶部或底部注册JavaScript。
$ this-> registerJs($(function(){
$('#popupModal'))。单击(函数(e){
e.preventDefault();
$('#modal')。modal('show')。find('。modal-content')
。 load($(this).attr('href'));
});
}););
i would like to pop up a modal when i click on a button inside grid view. is this possible with yii2 gridview?
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'time_zone',
'no_of_users',
'bill_name',
'bill_address',
'names.name',
'bill_state',
'bill_city',
'bill_postal',
'bill_mobile',
['header'=>'Plan Info',
'value'=> function($data)
{
//~ print_r($data);die();
return Html::a(Yii::t('app', ' {modelClass}', [
'modelClass' => 'details',
]), ['userdetails/plans','id'=>$data->id], ['class' => 'btn btn-success ']
);
},
'format' => 'raw'
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
in the above grid view i want a modal to popup when i click on the button 'details'.
thanks,
解决方案
Yes, it is possible. to achieve this follow below steps.
Add Modal
code above GridView
code.
<?php
yii\bootstrap\Modal::begin(['id' =>'modal']);
yii\bootstrap\Modal::end();
?>
After that add id
in your details button.
Like as,
[
'header'=>'Plan Info',
'value'=> function($data)
{
return Html::a(Yii::t('app', ' {modelClass}', [
'modelClass' => 'details',
]), ['userdetails/plans','id'=>$data->id], ['class' => 'btn btn-success', 'id' => 'popupModal']);
},
'format' => 'raw'
],
And than register JavaScript at top or bottom of view page.
$this->registerJs("$(function() {
$('#popupModal').click(function(e) {
e.preventDefault();
$('#modal').modal('show').find('.modal-content')
.load($(this).attr('href'));
});
});");
这篇关于在yii2的网格视图中弹出模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文