Answer the question
In order to leave comments, you need to log in
Why can pagination work incorrectly in GridViews loaded via Ajax?
Part of a view with Tab panels. The content is loaded by the script.
<?php
$js = <<< 'SCRIPT'
$('[data-toggle="tab-ajax"]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
targ = $this.attr('data-target');
$.get(loadurl, function(data) {
$(targ).html(data);
});
$this.tab('show');
return false;
});
SCRIPT;
$this->registerJs($js);
?>
<div class="nav-tabs-custom">
<ul class="nav nav-tabs tabs-up">
<li><?= Html::a('tab1', ['/site/tab1'], ['data-target' => '#tab1pane', 'data-toggle' => 'tab-ajax'])?></li>
<li><?= Html::a('tab2', ['/site/tab2'], ['data-target' => '#tab2pane', 'data-toggle' => 'tab-ajax'])?></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1pane"></div>
<div class="tab-pane" id="tab2pane"></div>
</div>
</div>
$dataProvider = new ActiveDataProvider([
'query' => Street::find(),
'pagination' => ['pageSize' => 10, 'pageParam' => 'tab1content',],
]);
Pjax::begin(['enablePushState' => true]);
echo GridView::widget([
'dataProvider' => $dataProvider,
'options' => ['id'=>'tab1content'],
]);
Pjax::end();
Answer the question
In order to leave comments, you need to log in
This is most likely because the content of the tab goes to display: none, when switching back - to display: block. In this case, it is necessary to reinitialize the function responsible for the logic of the content. In fact, instead, I would write a class-state for the content of the css tab (by the way, you have it), in which it does not need to go to display: none. For example:
.tab-pane{
pointer-events: none;
opacity: 0;
&.active{
pointer-events: auto;
opacity: 1;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question