From 719b906460c80e476c882af6104d6a3918223881 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 23 Aug 2017 14:07:42 +1200 Subject: [PATCH] DOCS Add use examples for GridFieldConfigurablePaginator --- README.md | 51 ++++++++++++++++++++++++------------------------ docs/en/index.md | 33 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index fda41b7..b5589c1 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,26 @@ -SilverStripe Grid Field Extensions Module -========================================= - -[![Build Status](https://travis-ci.org/silverstripe-australia/silverstripe-gridfieldextensions.svg?branch=master)](https://travis-ci.org/silverstripe-australia/silverstripe-gridfieldextensions) -[![Latest Stable Version](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/version.svg)](https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/releases) -[![Latest Unstable Version](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/v/unstable.svg)](https://packagist.org/packages/silverstripe-australia/gridfieldextensions) -[![Total Downloads](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/downloads.svg)](https://packagist.org/packages/silverstripe-australia/gridfieldextensions) -[![License](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/license.svg)](https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/blob/master/LICENSE.md) - -This module provides a number of useful grid field components: - -* `GridFieldAddExistingSearchButton` - a more advanced search form for adding - items. -* `GridFieldAddNewInlineButton` - builds on `GridFieldEditableColumns` to allow - inline creation of records. -* `GridFieldAddNewMultiClass` - lets the user select from a list of classes to - create a new record from. -* `GridFieldEditableColumns` - allows inline editing of records. -* `GridFieldOrderableRows` - drag and drop re-ordering of rows. -* `GridFieldRequestHandler` - a basic utility class which can be used to build - custom grid field detail views including tabs, breadcrumbs and other CMS - features. -* `GridFieldTitleHeader` - a simple header which displays column titles. - -See [docs/en/index.md](docs/en/index.md) for documentation and examples. +SilverStripe Grid Field Extensions Module +========================================= + +[![Build Status](https://travis-ci.org/silverstripe-australia/silverstripe-gridfieldextensions.svg?branch=master)](https://travis-ci.org/silverstripe-australia/silverstripe-gridfieldextensions) +[![Latest Stable Version](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/version.svg)](https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/releases) +[![Latest Unstable Version](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/v/unstable.svg)](https://packagist.org/packages/silverstripe-australia/gridfieldextensions) +[![Total Downloads](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/downloads.svg)](https://packagist.org/packages/silverstripe-australia/gridfieldextensions) +[![License](https://poser.pugx.org/silverstripe-australia/gridfieldextensions/license.svg)](https://github.com/silverstripe-australia/silverstripe-gridfieldextensions/blob/master/LICENSE.md) + +This module provides a number of useful grid field components: + +* `GridFieldAddExistingSearchButton` - a more advanced search form for adding + items. +* `GridFieldAddNewInlineButton` - builds on `GridFieldEditableColumns` to allow + inline creation of records. +* `GridFieldAddNewMultiClass` - lets the user select from a list of classes to + create a new record from. +* `GridFieldEditableColumns` - allows inline editing of records. +* `GridFieldOrderableRows` - drag and drop re-ordering of rows. +* `GridFieldRequestHandler` - a basic utility class which can be used to build + custom grid field detail views including tabs, breadcrumbs and other CMS + features. +* `GridFieldTitleHeader` - a simple header which displays column titles. +* `GridFieldConfigurablePaginator` - a paginator for GridField that allows customisable page sizes. + +See [docs/en/index.md](docs/en/index.md) for documentation and examples. diff --git a/docs/en/index.md b/docs/en/index.md index fb1e3be..5afe558 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -106,3 +106,36 @@ class Item extends DataObject { **Please NOTE:** There is a limitation when using `GridFieldOrderableRows` on unsaved data objects; namely, that it doesn't work as without data being saved, the list of related objects has no context. Please check `$this->ID` before adding the `GridFieldOrderableRows` component to the grid field config (or even, before adding the gridfield at all). +Configurable Paginator +---------------------- + +The `GridFieldConfigurablePaginator` component allows you to have a page size dropdown added to your GridField +pagination controls. The page sizes are configurable via the configuration system, or at call time using the public API. +To use this component you should remove the original paginator component first: + +```php +$gridField->getConfig() + ->removeComponentsByType('GridFieldPaginator') + ->addComponent(new GridFieldConfigurablePaginator()); +``` + +You can configure the page sizes with the configuration system. Note that merging is the default strategy, so to replace +the default sizes with your own you will need to unset the original first, for example: + +```php +# File: mysite/_config.php +Config::inst()->remove('GridFieldConfigurablePaginator', 'default_page_sizes'); +Config::inst()->update('GridFieldConfigurablePaginator', 'default_page_sizes', array(100, 200, 500)); +``` + +You can also override these at call time: + +```php +$paginator = new GridFieldConfigurablePaginator(100, array(100, 200, 500)); + +$paginator->setPageSizes(array(200, 500, 1000)); +$paginator->setItemsPerPage(500); +``` + +The first shown record will be maintained across page size changes, and the number of pages and current page will be +recalculated on each request, based on the current first shown record and page size.