diff --git a/code/GridFieldConfigurablePaginator.php b/code/GridFieldConfigurablePaginator.php index c147e09f..6ddfd073 100644 --- a/code/GridFieldConfigurablePaginator.php +++ b/code/GridFieldConfigurablePaginator.php @@ -159,6 +159,10 @@ public function getPreviousPage() public function setPageSizes(array $pageSizes) { $this->pageSizes = $pageSizes; + + // Reset items per page + $this->setItemsPerPage(current($pageSizes)); + return $this; } diff --git a/tests/GridFieldConfigurablePaginatorTest.php b/tests/GridFieldConfigurablePaginatorTest.php index cd584401..b16235a9 100644 --- a/tests/GridFieldConfigurablePaginatorTest.php +++ b/tests/GridFieldConfigurablePaginatorTest.php @@ -80,6 +80,20 @@ public function testGetTotalPages() $this->assertSame(3, $paginator->getTotalPages()); } + public function testItemsPerPageIsSetToFirstInPageSizesListWhenChanged() + { + $paginator = new GridFieldConfigurablePaginator(20, array(20, 40, 60)); + $paginator->setGridField($this->gridField); + + // Initial state, should be what was provided to the constructor + $this->assertSame(20, $paginator->getItemsPerPage()); + + $paginator->setPageSizes(array(50, 100, 200)); + + // Set via public API, should now be set to 50 + $this->assertSame(50, $paginator->getItemsPerPage()); + } + public function testGetCurrentPreviousAndNextPages() { $paginator = new GridFieldConfigurablePaginator(20, array(20, 40, 60));