Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change number of rows shown in GridView in Yii2

Tags:

gridview

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

like image 425
Paramone Avatar asked May 08 '15 09:05

Paramone


1 Answers

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:

  • BaseDataProvider $pagination
  • Pagination $pageSize
  • GridView $layout
like image 106
arogachev Avatar answered Sep 21 '22 13:09

arogachev