Merge pull request #4767 from tractorcow/pulls/3.2/fix-print-limit

BUG Fix print button only displaying first page
This commit is contained in:
Loz Calver 2015-11-12 09:29:25 +00:00
commit 5f17618096
2 changed files with 47 additions and 1 deletions

View File

@ -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) {

View File

@ -0,0 +1,46 @@
<?php
class GridFieldPrintButtonTest extends SapphireTest {
protected $extraDataObjects = array(
'GridFieldPrintButtonTest_DO'
);
public function setUp() {
parent::setUp();
// 42 items
for($i = 1; $i <= 42; $i++) {
$obj = new GridFieldPrintButtonTest_DO();
$obj->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'
);
}