Skip to content

Commit

Permalink
Added more documentation for nested gridfields.
Browse files Browse the repository at this point in the history
  • Loading branch information
forsdahl committed May 15, 2024
1 parent a9b0a70 commit c476ced
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This module provides a number of useful grid field components:
features.
* `GridFieldTitleHeader` - a simple header which displays column titles.
* `GridFieldConfigurablePaginator` - a paginator for GridField that allows customisable page sizes.
* `GridFieldNestedForm` - allows nesting of GridFields for managing relation records directly within
a parent GridField.

## Installation

Expand Down
29 changes: 29 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,32 @@ $grid->getConfig()->addComponent(GridFieldNestedForm::create());
// Usage with custom relation
$grid->getConfig()->addComponent(GridFieldNestedForm::create()->setRelationName('MyRelation'));
```

You can define your own custom GridField config for the nested GridField configuration by implementing a `getNestedConfig`
on your nested model (should return a `GridField_Config` object).
```php
class NestedObject extends DataObject
{
private static $has_one = [
'Parent' => ParentObject::class
];

public function getNestedConfig(): GridFieldConfig
{
$config = new GridFieldConfig_RecordViewer();
return $config;
}
}
```

You can also modify the default config (a `GridFieldConfig_RecordEditor`) via an extension to the nested model class, by implementing
`updateNestedConfig`, which will get the config object as the first parameter.
```php
class NestedObjectExtension extends DataExtension
{
public function updateNestedConfig(GridFieldConfig &$config)
{
$config->removeComponentsByType(GridFieldPaginator::class);
}
}
```

0 comments on commit c476ced

Please sign in to comment.