From fea1158d193ed4d037df94101e3b3f2d24a6ce49 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 12 Nov 2015 14:59:08 +1300 Subject: [PATCH] BUG Fix print button only displaying first page --- forms/gridfield/GridFieldPrintButton.php | 2 +- .../gridfield/GridFieldPrintButtonTest.php | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/forms/gridfield/GridFieldPrintButtonTest.php diff --git a/forms/gridfield/GridFieldPrintButton.php b/forms/gridfield/GridFieldPrintButton.php index 5b5803b4f..1e25a8d27 100644 --- a/forms/gridfield/GridFieldPrintButton.php +++ b/forms/gridfield/GridFieldPrintButton.php @@ -186,7 +186,7 @@ class GridFieldPrintButton implements GridField_HTMLProvider, GridField_ActionPr $items = $gridField->getManipulatedList(); $itemRows = new ArrayList(); - foreach($items as $item) { + foreach($items->limit(null) as $item) { $itemRow = new ArrayList(); foreach($printColumns as $field => $label) { diff --git a/tests/forms/gridfield/GridFieldPrintButtonTest.php b/tests/forms/gridfield/GridFieldPrintButtonTest.php new file mode 100644 index 000000000..384705908 --- /dev/null +++ b/tests/forms/gridfield/GridFieldPrintButtonTest.php @@ -0,0 +1,46 @@ +Name = "Object {$i}"; + $obj->write(); + } + } + + public function testLimit() { + $list = GridFieldPrintButtonTest_DO::get(); + + $button = new GridFieldPrintButton(); + $button->setPrintColumns(array('Name' => 'My Name')); + + // Get paginated gridfield config + $config = GridFieldConfig::create() + ->addComponent(new GridFieldPaginator(10)) + ->addComponent($button); + $gridField = new GridField('testfield', 'testfield', $list, $config); + $controller = new Controller(); + $form = new Form($controller, 'Form', new FieldList($gridField), new FieldList()); + + // Printed data should ignore pagination limit + $printData = $button->generatePrintData($gridField); + $rows = $printData->ItemRows; + $this->assertEquals(42, $rows->count()); + } +} + +class GridFieldPrintButtonTest_DO extends DataObject { + private static $db = array( + 'Name' => 'Varchar' + ); +}