【问题标题】:Yii2 gridview - modal only display in other table row if i expand first rowYii2 gridview - 如果我展开第一行,模态仅显示在其他表格行中
【发布时间】:2020-04-28 06:07:37
【问题描述】:

我正在使用 kartik\grid\GridView 和 kartik\grid\ExpandRowColumn。在 \kartik\grid\ExpandRowColumn gridview 下,我使用模态来创建代码值。如果我继续展开表格的第一行,则单击按钮新代码值 expandRowColumn 的每一行都会弹出模态。但是如果我折叠第一行并展开任何其他行并单击按钮新代码值模式不会弹出问题。

有人可以帮助我吗?我看到这里有相同问题的未回答主题Yii2 gridview - modal only display when click on first row

code-value-master/index.php

<?=
GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        [
            'class' => '\kartik\grid\ExpandRowColumn',
            'value' => function ($model, $key, $index, $column) {
                return GridView::ROW_COLLAPSED;
            },
            'detail' => function ($model, $key, $index, $column) {
                $searchModel = new app\models\CodeValueSearch();
                $searchModel->code_type = $model->code_type;
                $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

                return Yii::$app->controller->renderPartial('_codevalue', [
                            'searchModel' => $searchModel,
                            'dataProvider' => $dataProvider,
                            'model' => $model,
                ]);
            },
                    'expandIcon' => '<span class="glyphicon glyphicon-plus"></span>',
                    'collapseIcon' => '<span class="glyphicon glyphicon-minus"></span>',
                ],

                'code_type_lbl',

                ['class' => 'yii\grid\ActionColumn', 'template' => '{update}'],
            ],
        ]);
        ?>

code-value-master/_codevalue.php

    <?php
    echo Html::button('New Code Value', ['value' => Url::to(['code-value/create', 'cid' => $model->code_type]),
        'title' => 'Create Client Contact', 'class' => 'modalBtnCreate btn btn-success']);
    ?>

    <?php

    Modal::begin([

        'header' => '<h4>Create Code Value</h4>',
        'id' => 'modalCreate',
        'size' => 'modal-lg',
    ]);

    echo "<div class='modalContentCreate'></div>";
    Modal::end();
    ?>

    <?php
    $this->registerJs("$(function() {
       $('.modalBtnCreate').click(function(e) {
        e.preventDefault();
         $('#modalCreate').modal('show')
         .find('.modalContentCreate')
         .load($(this).attr('value'));
       });
    });");
?>

【问题讨论】:

    标签: php gridview yii2 kartik-v


    【解决方案1】:

    将此添加到您的 code-value-master/index.php。

    <div class="modal remote fade" id="codevalueform">
            <div class="modal-dialog">
                <div class="modal-content loader-lg"></div>
            </div>
    </div>
    

    在 _codevalue.php 中添加这个

    <?=Html::a('New Code Value <span class="glyphicon glyphicon-plus"></span>',
                        ['/code-value/create','cid'=> $model->code_type], 
                        [
                            'title' => 'Add',
                            'data-toggle'=>'modal',
                            'data-target'=>'#codevalueform',
                        ]
                       );
                    ?>
    

    现在在代码值控制器中

    public function actionCreate($cid){
        $modell=//your Code here
        return $this->renderAjax('create_form', [
            'model' => $model]);
       }
    

    现在创建视图文件,例如:create_form.php

    <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">New Code Value </h4>
    </div>
    <div class="modal-body">
    
    </div>
    

    运行代码,这应该可以工作。

    【讨论】:

    • 感谢您抽出宝贵时间解决了我的问题,但在模态代码类型中,值不是动态的。我通过将 modal (id => modalCreate) 添加到 code-value-master/index.php 而不是 code-value-master/_codevalue.php 来解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多