Change pagination link in yii\grid\GridView

Viewed 1653

I'm using GridView with Pjax in my view file in my Yii2 project like this:

<?php
Pjax::begin();
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'person.name',
        'person.email',
        'person.dob',
    ],
]);
Pjax::end();
?>

I need to redirect user to different URL when pagination.

How do I change pagination links?

1 Answers

You need to use the route option for the pagination object used when calling the ActiveDataProvider in the search model's search() function

Use the route property in the following way and change accordingly in the search() function

$dataProvider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'pageSize' => 5,
        'route' => 'controller/action'
    ]
]);
Related