diff --git a/demos/collection/grid.php b/demos/collection/grid.php index 1dd616cc05..28a407e3a2 100644 --- a/demos/collection/grid.php +++ b/demos/collection/grid.php @@ -105,4 +105,4 @@ }); // setting ipp with an array will add an ItemPerPageSelector to paginator -$grid->setIpp([10, 100, 1000]); +$grid->setIpp([10, 50, 100, 1000]); diff --git a/src/Grid.php b/src/Grid.php index b58d8e9f96..a262f06612 100644 --- a/src/Grid.php +++ b/src/Grid.php @@ -48,7 +48,7 @@ class Grid extends View public $paginator; /** @var int Number of items per page to display. */ - public $ipp = 50; + public $ipp = 10; /** * Calling addActionButton will add a new column inside $table, and will be re-used @@ -214,13 +214,18 @@ public function setIpp($ipp, $label = 'Items per page:'): void * * @return $this */ - public function addItemsPerPageSelector(array $items = [10, 100, 1000], $label = 'Items per page:') + public function addItemsPerPageSelector(array $items = [10, 50, 100, 1000], $label = 'Items per page:') { $ipp = (int) $this->container->stickyGet('ipp'); - if ($ipp) { + + /* + * If $ipp is 0 don't set $this->ipp to the first item as that always sets the viewed selection + * to the first item in the list. If we actually track the ipp in the app we want it to set and + * show the correct value, as it was before reload or other events, before this change it only set the selected ipp value but showed the first item. + * Default ipp in this class is 50, that will be showed when nothing is selected. + */ + if ($ipp > 0) { $this->ipp = $ipp; - } else { - $this->ipp = $items[0]; } $pageLength = ItemsPerPageSelector::addTo($this->paginator, ['pageLengthItems' => $items, 'label' => $label, 'currentIpp' => $this->ipp], ['afterPaginator']);