Skip to content

Commit

Permalink
FIX When setting the page sizes, reset items per page to the first value
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Aug 31, 2017
1 parent f80fc03 commit 58200f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions code/GridFieldConfigurablePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/GridFieldConfigurablePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 58200f8

Please sign in to comment.