Paramone
Paramone

Reputation: 2724

Change number of rows shown in GridView in Yii2

I'm trying to change the amount of rows shown on the gridView (Yii2) but I couldn't find anything in their documentation.

Is it even possible or do I have to have to use another extension? (Kartik for example.)

Also, is it possible to remove "Showing x of x items" as shown beneath?

enter image description here

Upvotes: 17

Views: 16157

Answers (2)

SunnyDay
SunnyDay

Reputation: 99

or like that

public function actionIndex() {
 $searchModel = new SettingSearch();
 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
 $dataProvider->pagination = ['pageSize' => 100];

 return $this->render('index', [
  'searchModel' => $searchModel,
  'dataProvider' => $dataProvider,
  ]);
}

Upvotes: 8

arogachev
arogachev

Reputation: 33538

To change the number of items displayed per page, you need to set pagination in your data provider.

Example:

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

As for removing information about displayed items you need to remove summary from layout:

<?= GridView::widget([
    ...
    'layout' => "{items}\n{pager}",
]) ?>

Official docs:

Upvotes: 18

Related Questions