Hi everybody
I’m new in yii(2) and I have problem with GridView filter via pjax:
I have a GridView List.
I can filter the gird usinig filter and pjax.
On the same page theres a button to add new record.
On button click, a modal form opens and the form to create a new record is loaded via ajax.
After closing the modal (without saving), I can’t filter the grid anymore.
When I try to filter, it redirects me to the create Action (from modal form).
It seems, that the ajax call is manipulating the url.
I have no clue whats the problem.
My goal to archive is to refresh the GridView via pjax, after creating a new record in the modal.
I hope you guys can help me.
Here is my code so far:
index.php
<?= Button::widget([
'label' => 'Neue Lieferung anlegen',
'encodeLabel' => false,
'options' => [
'data-url' => Url::toRoute(['/supplier_orders/deliveries/create']),
'class' => 'btn btn-success open-modal'
],
]);
?>
<? Modal::begin([
'header' => 'Lieferantenbestellung',
'size' => Modal::SIZE_LARGE,
'id' => 'modal-form',
]);
?>
<div id="modal-content"></div>
<? Modal::end() ?>
<? yii\widgets\Pjax::begin([
'options' => [
'id' => 'supplier-deliveries-grid',
'class' => 'pjax-grid',
]
])?>
<?= GridView::widget([
'layout' => "{items}\n{pager}",
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
//...
[
'class' => 'yii\grid\ActionColumn',
'contentOptions' => ['style'=>'width: 97px'],
'buttons' => [
'view' => function($url, $model) {
return Html::a('<button class="btn btn-xs btn-success"><span class="glyphicon glyphicon-eye-open"></span></button>', ['view', 'id' => $model['id']]);
},
'update' => function($url, $model) {
if (!$model->hasLinkedOrders()) {
return Button::widget([
'label' => '<span class="glyphicon glyphicon-pencil"></span>',
'encodeLabel' => false,
'options' => [
'data-url' => Url::toRoute(['/supplier_orders/deliveries/update', 'id' => $model['id']]),
'class' => 'btn btn-info btn-xs open-modal'
],
]);
} else {
return "";
}
},
'delete' => function($url, $model) {
return Html::a('<button class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></button>', ['delete', 'id' => $model['id']]);
},
],
],
],
]); ?>
<? yii\widgets\Pjax::end() ?>
app.js
$('body').on('click', '.open-modal', function() {
$('#modal-form').modal('show')
.find('#modal-content')
.load($(this).attr('data-url'));
});