4

I have been trying to find information on how to remove pagination on GridFields in SS3 and display all (or at least more) DataObjects in a CMS GridField view.

I am specifically using SortableGridFields to allow sorting.

The interface defaults to load 15 DataObjects at a time.

  1. Is there a way to remove pagination altogether ?
  2. Is there a way to increase the limit to, say, 50 ?

Here is the current code for the specific GridField:

class ProjectPage extends Page {
// ORM
public static $has_many = array(
    "Media" => "ProjectMediaObject"
);
// Page fields in CMS
public function getCMSFields() {
    // add media GridField
    // config
    $config = GridFieldConfig_RecordEditor::create();
    $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
        "Thumbnail" => "Thumbnail",
        "hasVideo" => "Video"
    ));
    $config->addComponent(new GridFieldBulkEditingTools());
    $config->addComponent(new GridFieldBulkImageUpload());
    $config->addComponent(new GridFieldSortableRows("SortOrder"));
    // grid
    $media = new GridField("Media", "ProjectMediaObject", $this->Media(), $config);
    $fields->addFieldToTab("Root.Media", $media);
}

}

The code works perfectly, what I'm looking for is some config variable I seem to be missing. Otherwise, it could maybe not be possible for some-or-other reason...

Atari
  • 143
  • 2
  • 10
  • looking at the code, it seems you're using an old version of `GridFieldBulkImageUpload`. I would advise updating it, download the latest master branch https://github.com/colymba/GridFieldBulkEditingTools and use only `$config->addComponent(new GridFieldBulkImageUpload());` – colymba Oct 28 '13 at 14:47

1 Answers1

7

there is a few options:

GridFieldConfig_RecordEditor take an argument which is used for item per page.

$config = GridFieldConfig_RecordEditor::create(50);

or set the item per page on the component:

$config->getComponentByType('GridFieldPaginator')->setItemsPerPage(50);

or remove pagination (and related components):

$config->removeComponentsByType('GridFieldPaginator');
$config->removeComponentsByType('GridFieldPageCount');
colymba
  • 2,644
  • 15
  • 15
  • Setting the number of items works perfectly, thank you. However, removing the GridField throws the following error: **[User Error] Uncaught LogicException: GridFieldPageCount relies on a GridFieldPaginator to be added to the same GridField, but none are present.** This could be due to the system still running on SS v3.0, but it is too complex to "simply" upgrade, sadly. I will give this a test on a v3.1 implementation when I get the chance. – Atari Oct 28 '13 at 15:48
  • 1
    The error comes from another component `GridFieldPageCount` that relies on `GridFieldPaginator`, just needs to be removed too. See updated answer above. – colymba Oct 28 '13 at 15:59
  • The complete answer is above for both increasing the number of elements and removing pagination altogether, thanks again Colymba :-) – Atari Oct 30 '13 at 16:19