I am using kartik\grid\GridView and kartik\grid\ExpandRowColumn. Under \kartik\grid\ExpandRowColumn gridview I am using modal to create code value. Modal pop up on each and every row on click button New Code Value of expandRowColumn if i keep expand first row of table. But the problem if i collapsed first row and expand any other row and click of button New Code Value modal does not pop up.
Can someone help me? I saw that there is an unanswered topic for the same problem here 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'));
});
});");
?>
Add this to your 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>
Add this inside _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',
]
);
?>
Now inside Code-value Controller
public function actionCreate($cid){
$modell=//your Code here
return $this->renderAjax('create_form', [
'model' => $model]);
}
Now create View file for example: 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>
Run the code, this should work.