Paging and Filter in Yii2 Gridview

You need to add pagination option in ActiveDataProvider in search model and also put where or andWhere at $query condition.

$query = modalName::find()->andWhere([ 'status' => ['open', 'pending'] ]);

$dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [ 'pageSize' => 10 ],
        ]);

    $searchModel = new PersonSearch();
    $dataProvider = $searchModel->search(
    Yii::$app->request->queryParams);
    $dataProvider->pagination = ['pageSize' => 10,];

Following Yii's getting started tutorial, $dataProvider has a setPagination method.

...
/** Basic generated code from Gii **/
$searchModel = new AlbumSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

/** Paginate & Show 5 items in the table */
$dataProvider->setPagination(['pageSize' => 5]); 
...

The top answer is excessive because it creates a new ActiveDataProvider(...) and re-inserts its own query just to set the pagination. Please be guided.