【发布时间】: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