R
R
ruslannasrutdinov2015-06-09 12:42:34
Yii
ruslannasrutdinov, 2015-06-09 12:42:34

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]);

View code
<?=
                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

3 answer(s)
O
Oleg, 2015-06-18
@ruslannasrutdinov

You need to change the parameter pageParamin 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,
            ],
        ]);

www.yiiframework.com/doc-2.0/yii-data-pagination.html

C
corpsepk, 2015-06-18
@corpsepk

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,
]);

L
lycifer3, 2016-05-16
@lycifer3

Do not tell me the same question, only with scrollPager there is only one button for scrolling, but it loads both entities, although they have different pageParam

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question