Answer the question
In order to leave comments, you need to log in
Yii 2. Two listviews on one page. How to make a page navigator for each listview separately?
You need to make a page navigator for each listview separately. At the moment, if I switch the page in one listview to the second, both listviews are switched.
Controller code.
$provider_top = new ActiveDataProvider([
'query' => Object::find()->where(['status' => 1])->orderBy(['visits'=>SORT_DESC]),
'pagination' => [
'pageSize' => 6,
],
]);
$provider_new = new ActiveDataProvider([
'query' => Object::find()->where(['status' => 1])->orderBy(['added_on'=>SORT_DESC]),
'pagination' => [
'pageSize' => 6,
],
]);
return $this->render('index',['provider_top'=>$provider_top, 'provider_new'=>$provider_new]);
<?=
ListView::widget([
'dataProvider' => $provider_top,
'itemView' => '_view',
'summary' => '',
'options' => ['class'=>'row'],
'itemOptions' => ['class'=>'col-md-4 city-item']
])
?>
<?=
ListView::widget([
'dataProvider' => $provider_new,
'itemView' => '_view',
'summary' => '',
'options' => ['class'=>'row'],
'itemOptions' => ['class'=>'col-md-4 city-item']
])
?>
Answer the question
In order to leave comments, you need to log in
You need to change the parameter pageParam
in the objectyii\data\Pagination
$provider_top = new ActiveDataProvider([
'query' => Object::find()->where(['status' => 1])->orderBy(['visits'=>SORT_DESC]),
'pagination' => [
'pageParam' => 'page-top', # <-------------
'pageSize' => 6,
],
]);
$provider_new = new ActiveDataProvider([
'query' => Object::find()->where(['status' => 1])->orderBy(['added_on'=>SORT_DESC]),
'pagination' => [
'pageParam' => 'page-new', # <-------------
'pageSize' => 6,
],
]);
Of. docks, with ListView everything is the same:
Multiple GridViews on one page
use yii\grid\GridView;
$userProvider->pagination->pageParam = 'user-page';
$userProvider->sort->sortParam = 'user-sort';
$postProvider->pagination->pageParam = 'post-page';
$postProvider->sort->sortParam = 'post-sort';
echo '<h1>Users</h1>';
echo GridView::widget([
'dataProvider' => $userProvider,
]);
echo '<h1>Posts</h1>';
echo GridView::widget([
'dataProvider' => $postProvider,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question