From 90ada9871e0b43d72612e8efd24fa15565c78969 Mon Sep 17 00:00:00 2001 From: ajshort Date: Sat, 9 Feb 2013 16:01:26 +1100 Subject: [PATCH] Add usage documentation. Closes #3. --- README.md | 2 ++ docs/en/index.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 docs/en/index.md diff --git a/README.md b/README.md index 886151f..550413a 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,5 @@ This module provides a number of useful grid field components: * `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. + +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 new file mode 100644 index 0000000..369a9b3 --- /dev/null +++ b/docs/en/index.md @@ -0,0 +1,76 @@ +Grid Field Extensions +===================== + +Add Existing Search +------------------- + +The `GridFieldAddExistingSearchButton` component provides a more complete solution for adding +existing records than a basic autocomplete. It uses the search context constructed by the model +class to provide the search form. + +```php +$grid->getConfig()->addComponent(new GridFieldAddExistingSearchButton())); +``` + +Inline Editing +-------------- + +This example replaces the default data columns component with an inline editable one, and the +default add new button with one that adds new records inline. + +```php +$grid = new GridField( + 'ExampleGrid', + 'Example Grid', + $this->Items(), + GridFieldConfig_RecordEditor::create() + ->removeComponentsByType('GridFieldAddNewButton') + ->removeComponentsByType('GridFieldDataColumns') + ->addComponent(new GridFieldEditableColumns(), 'GridFieldEditButton') + ->addComponent(new GridFieldAddNewInlineButton()) +); +``` + +You can customise the form fields that are used in the grid by calling `setDisplayFields` on the +inline editing component. By default field scaffolding will be used. + +```php +$grid->getConfig()->getComponentsByType('GridFieldEditableColumns')->setDisplayFields(array( + 'FirstField' => function($record, $column, $grid) { + return new TextField($column); + }, + 'SecondField' => array( + 'title' => 'Custom Title', + 'field' => 'ReadonlyField' + ) +)); +``` + +Multi Class Adding +------------------ + +The `GridFieldAddNewMultiClass` allows the user to select the record type to create when creating +a new record. By default it allows them to select the model class for the grid field, or any +subclasses. You can control the createable classes using the `setClasses` method. + +```php +$grid->getConfig() + ->removeComponentsByType('GridFieldAddNewButton') + ->addComponent(new GridFieldAddNewMultiClass()); +``` + +Orderable Rows +-------------- + +The `GridFieldOrderableRows` component allows drag-and-drop reordering of any list type. The field +used to store the sort is set by passing a constructor parameter to the component, or calling +`setSortField`. For `many_many` relationships, the sort field should normally be an extra field on +the relationship. + +```php +// Basic usage, defaults to "Sort" for the sort field. +$grid->getConfig()->addComponent(new GridFieldOrderableRows()); + +// Specifying the sort field. +$grid->getConfig()->addComponent(new GridFieldOrderableRows('SortField')); +```