带弹出窗口的Gridview

时间:2016-09-28 09:53:43

标签: gridview yii2

我想在gridview中使用jquery按钮点击事件设计一个自定义弹出窗口(不像删除) 按钮位于操作列ob gridview

如何添加带有每行ID的弹出窗口

1 个答案:

答案 0 :(得分:2)

试试这个, 插入

use yii\helpers\Url;  
use yii\bootstrap\Modal;  

进入你的index.php

[
    'class'    => 'yii\grid\ActionColumn',
    'header'   => 'Action',
    'template' => '{view} {update} {delete} {your_link}',
    'buttons'  => [

        'your_link' => function ($url, $model) {
            $url = Url::to(['controller / action', 'id' => $model->id]);

            return Html::a(' <span class="glyphicon glyphicon-eye-open" title = "Tooltip Name" ></span> ', 'javascript:void(0)', ['class' => 'anyClassName', 'value' => $url]);
        },
    ],
],

定义模态并将此JS注册到您的索引文件

<?php 

Modal::begin([
    'id'     => "modal",
    'header' => '<h3>Assign Farmers to other Farm Mitra</h3>',
]);

echo "<div id='modalContent'></div>";
Modal::end();


$this->registerJs(
    "$(document).on('ready pjax:success', function() {
            $('.list').click(function(e){
               e.preventDefault(); //for prevent default behavior of <a> tag.
               $('#modal').modal('show').find('#modalContent').load($(this).attr('value'));
           });
        });
    ");

?>
相关问题