Yii2 gridview - 如果我展开第一行,模式仅显示在其他 table 行
Yii2 gridview - modal only display in other table row if i expand first row
我正在使用 kartik\grid\GridView 和 kartik\grid\ExpandRowColumn。在 \kartik\grid\ExpandRowColumn gridview 下,我使用模态来创建代码值。如果我继续展开 table 的第一行,则在单击按钮 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'));
});
});");
?>
将此添加到您的 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">×</button>
<h4 class="modal-title">New Code Value </h4>
</div>
<div class="modal-body">
</div>
运行 代码,这应该可以。
我正在使用 kartik\grid\GridView 和 kartik\grid\ExpandRowColumn。在 \kartik\grid\ExpandRowColumn gridview 下,我使用模态来创建代码值。如果我继续展开 table 的第一行,则在单击按钮 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'));
});
});");
?>
将此添加到您的 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">×</button>
<h4 class="modal-title">New Code Value </h4>
</div>
<div class="modal-body">
</div>
运行 代码,这应该可以。