Permalink
Browse files

API Make default gridfield paging configurable

Documentation improved
  • Loading branch information...
1 parent 36d9255 commit 892b440115a388db354abf0b885eb03be0318cf1 @tractorcow tractorcow committed Apr 11, 2014
Showing with 31 additions and 2 deletions.
  1. +20 −0 docs/en/reference/grid-field.md
  2. +11 −2 forms/gridfield/GridFieldPaginator.php
@@ -98,6 +98,24 @@ A config object can be either injected as the fourth argument of the GridField c
$gridField = new GridField('pages', 'All pages', SiteTree::get());
$gridField->setConfig(GridFieldConfig_Base::create());
+By default the `[api:GridFieldConfig_Base]` constructor takes a single parameter to specify the number
+of items displayed on each page.
+
+ :::php
+ // I have lots of items, so increase the page size
+ $myConfig = GridFieldConfig_Base::create(40);
+
+The default page size can also be tweaked via the config. (put in your mysite/_config/config.yml)
+
+ :::yaml
+ // For updating all gridfield defaults system wide
+ GridFieldPaginator:
+ default_items_per_page: 40
+
+Note that for [/reference/modeladmin](ModelAdmin) sections the default 30 number of pages can be
+controlled either by setting the base `ModelAdmin.page_length` config to the desired number, or
+by overriding this value in a custom subclass.
+
The framework comes shipped with some base GridFieldConfigs:
### Table listing with GridFieldConfig_Base
@@ -246,6 +264,8 @@ Here is a list of components for generic use:
- `[api:GridFieldDeleteAction]`
- `[api:GridFieldViewButton]`
- `[api:GridFieldEditButton]`
+ - `[api:GridFieldExportButton]`
+ - `[api:GridFieldPrintButton]`
- `[api:GridFieldPaginator]`
- `[api:GridFieldDetailForm]`
@@ -9,9 +9,17 @@
class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipulator, GridField_ActionProvider {
/**
+ * Specifies default items per page
+ *
+ * @config
+ * @var int
+ */
+ private static $default_items_per_page = 15;
+
+ /**
* @var int
*/
- protected $itemsPerPage = 15;
+ protected $itemsPerPage;
/**
* Which template to use for rendering
@@ -30,7 +38,8 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
* @param int $itemsPerPage - How many items should be displayed per page
*/
public function __construct($itemsPerPage=null) {
- if($itemsPerPage) $this->itemsPerPage = $itemsPerPage;
+ $this->itemsPerPage = $itemsPerPage
+ ?: Config::inst()->get('GridFieldPaginator', 'default_items_per_page');
}
/**

0 comments on commit 892b440

Please sign in to comment.