[size="4"]
Hello everyone!
I’m having problems with Yii2 GridViews and Pjax. I am showing a first GridView which expands to show another GridView via ExpandRowColumn widget. I had to remove Pjax options from the parent view for the inner Gridview to show properly.
It renders fine and filters correctly but I have problems when trying to force reloading the pjax container. When I call on pjax reload, the inner view seems to update fine but it also refreshes the whole page afterwards.
The parent GridView has the following ExpandRowColumn:
['class' => 'kartik\grid\ExpandRowColumn',
'width' => '50px',
'value' => function ($model, $key, $index, $column) {
return GridView::ROW_COLLAPSED;
},
'detailUrl' => Url::to(['/mainview/innerview']),
'headerOptions' => ['class' => 'kartik-sheet-style'],
'enableRowClick' => true,
]
And this is my inner view:
echo \backoffice\components\BOGridView::widget([
'id' => $dataProvider->id . '-listing',
'dataProvider' => $dataProvider,
'pjax' => true,
'pjaxSettings' => [
'neverTimeout' => true,
'options' => [
'id' => $dataProvider->id . '-pjax',
'enablePushState' => false,
'clientOptions' => [
'method' => 'POST',
'skipOuterContainers' => true,
]
]
],
'filterModel' => $searchModel,
'filterUrl' => ['innerview', 'ViewId' => $dataProvider->id],
...
]);
$this->registerJS("
$('.js-save-batch-editable-form').on('click', function() {
if ($('#batchEditForm-".$dataProvider->id." input[name=\"apply[]\"]:checked').length >0) {
var frm = $('#batchEditForm-".$dataProvider->id."');
$.ajax({
type: frm.attr('method'),
url: '/mainview/action',
data: frm.serialize(),
success: function (data){
$.pjax.reload({'container': '#".$dataProvider->id."-pjax',
'url': '/mainview/innerview',
'skipOuterContainers': true, 'push': false});
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error while updating: ' + errorThrown);
}
});
} else {
alert('Please select at least one item');
}
});");
Nesting GridViews didn’t seem like a good idea since the beggining but it seems i have managed to get it working on most cases except this. I don’t need the parent GridView to use Pjax but it may have something to do…
Please help, I’m gonna cry a river.
Any help will be appreciated.
[/size]