From 58200f847fbdeeae6f593274846e939e482cbdd5 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 31 Aug 2017 14:35:52 +1200 Subject: [PATCH] FIX When setting the page sizes, reset items per page to the first value --- code/GridFieldConfigurablePaginator.php | 4 ++++ tests/GridFieldConfigurablePaginatorTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/code/GridFieldConfigurablePaginator.php b/code/GridFieldConfigurablePaginator.php index c147e09..6ddfd07 100644 --- a/code/GridFieldConfigurablePaginator.php +++ b/code/GridFieldConfigurablePaginator.php @@ -159,6 +159,10 @@ class GridFieldConfigurablePaginator extends GridFieldPaginator 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 cd58440..b16235a 100644 --- a/tests/GridFieldConfigurablePaginatorTest.php +++ b/tests/GridFieldConfigurablePaginatorTest.php @@ -80,6 +80,20 @@ class GridFieldConfigurablePaginatorTest extends SapphireTest $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));