Change the number of rows shown in a gridview in Yii2

I am trying to change the number of rows shown in gridView (Yii2), but I did not find anything in their documentation.

Is this possible, or do I need to use another extension? (E.g. Kartik).

Also, is it possible to remove the "Display x elements x" as shown below?

enter image description here

+9
gridview yii2
source share
2 answers

To change the number of items displayed on a page, you need to set pagination to the data provider.

Example:

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

As for deleting information about the displayed items, you need to remove the summary from the layout :

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

Official documents:

+13
source share

or the like

 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, ]); } 
+5
source share

All Articles