在 yii2 的网格视图中弹出模态 [英] Modal pop up in grid view in yii2
本文介绍了在 yii2 的网格视图中弹出模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击网格视图中的按钮时,我想弹出一个模式.这可能与 yii2 gridview 一起使用吗?
= GridView::widget(['数据提供者' =>$数据提供者,'过滤器模型' =>$搜索模型,'列' =>[['类' =>'yiigridSerialColumn'],'时区','no_of_users','bill_name','账单地址','names.name','bill_state','bill_city','bill_postal','bill_mobile',['header'='计划信息','值'=>功能($数据){//~ print_r($data);die();return Html::a(Yii::t('app', ' {modelClass}', ['模型类' =>'细节',]), ['userdetails/plans','id'=>$data->id], ['class' =>'btn btn-成功']);},'格式' =>'生的'],['类' =>'yiigridActionColumn'],],]);?>
在上面的网格视图中,当我单击详细信息"按钮时,我希望弹出一个模式.
谢谢,
解决方案
是的,这是可能的.要实现这一点,请按照以下步骤操作.
在GridView
代码上方添加Modal
代码.
'modal']);yiiootstrapModal::end();?>
然后在您的详细信息按钮中添加 id
.就像,
然后在视图页面的顶部或底部注册 JavaScript.
$this->registerJs("$(function() {$('#popupModal').click(function(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' => 'yiigridSerialColumn'],
'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' => 'yiigridActionColumn'],
],
]); ?>
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
yiiootstrapModal::begin(['id' =>'modal']);
yiiootstrapModal::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屋!
查看全文