首页 > 其他 > 详细

yii2中使用modal弹窗之结合gridview的使用

时间:2020-02-17 09:54:58      阅读:88      评论:0      收藏:0      [点我收藏+]

1、gridview的操作增加[更新]按钮,并指定data-toggle data-target class以及data-id的值?

 
[
    ‘class‘ => ‘yii\grid\ActionColumn‘,
    ‘template‘ => ‘{update}‘, 
    ‘buttons‘ => [
        ‘update‘ => function ($url, $model, $key) {
            return Html::a(‘更新‘, ‘#‘, [
                ‘data-toggle‘ => ‘modal‘,
                ‘data-target‘ => ‘#update-modal‘,
                ‘class‘ => ‘data-update‘, 
                ‘data-id‘ => $key,  //所传参数
            ]);
        },
    ],
],
2、为更新添加modal?
<?php 
use yii\bootstrap\Modal;
// 更新操作
Modal::begin([
    ‘id‘ => ‘update-modal‘,
    ‘header‘ => ‘<h4 class="modal-title">更新</h4>‘,
    ‘footer‘ => ‘<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>‘,
]); 
$requestUpdateUrl = Url::toRoute(‘update‘);
$updateJs = <<<JS
    $(‘.data-update‘).on(‘click‘, function () {
        $.get(‘{$requestUpdateUrl}‘, { id: $(this).closest(‘tr‘).data(‘key‘) },
            function (data) {
                $(‘.modal-body‘).html(data);
            }  
        );
    });
JS;
$this->registerJs($updateJs);
Modal::end();
?>
3、修改我们的update方法
public function actionUpdate($id)
{
    $model = $this->findModel($id);
    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        return $this->redirect([‘index‘]);
    } else {
        return $this->renderAjax(‘update‘, [
            ‘model‘ => $model,
        ]);
    }
}

yii2中使用modal弹窗之结合gridview的使用

原文:https://www.cnblogs.com/phplzx/p/12320336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!