Yii2 gridview-如果我展开第一行,模式仅显示在其他表行中

问题描述 投票:0回答:1

我正在使用kartik \ grid \ GridView和kartik \ grid \ ExpandRowColumn。在\ kartik \ grid \ ExpandRowColumn gridview下,我使用模态来创建代码值。如果我不断扩展表的第一行,则会在单击按钮newRowColumn的New Code Value的每一行上弹出模态。但是,如果我折叠第一行并展开其他任何行,然后单击“新代码值”模态按钮,则不会弹出问题。

有人可以帮我吗?我看到这里有一个相同问题的未解答主题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个回答
0
投票

将此添加到您的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>

运行代码。这应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.