mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Added more documentation for nested gridfields.
This commit is contained in:
parent
a9b0a70155
commit
c476cedff0
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user