The grid field system in Silverstripe 3 has a number of preset config options – here’s what they do, and what they look like:
No Config
If we don’t add any config options, the grid field just displays a list of items… We can’t view the record details, or edit anything though…
1 2 |
$gridfield =newGridField("RegisterEvents","RegisterEvent", $this->RegisterEvents()); $fields->addFieldToTab('Root.Events', $gridfield); |
$gridfield = new GridField(“RegisterEvents”, “RegisterEvent”, $this->RegisterEvents());
$fields->addFieldToTab(‘Root.Events’, $gridfield);
GridFieldConfig_RecordViewer
1 2 3 |
$gridFieldConfig =GridFieldConfig_RecordViewer::create(); $gridfield =newGridField("RegisterEvents","RegisterEvent", $this->RegisterEvents(), $gridFieldConfig); $fields->addFieldToTab('Root.Events', $gridfield); |
This option just adds in the ability to click the magnifying glass and view the details of each item – but not edit anything.
GridFieldConfig_RecordEditor
1 2 3 |
$gridFieldConfig =GridFieldConfig_RecordEditor::create(); $gridfield =newGridField("RegisterEvents","RegisterEvent", $this->RegisterEvents(), $gridFieldConfig); $fields->addFieldToTab('Root.Events', $gridfield); |
Now we’re starting to get something useful – a list that lets us Add, View, and Remove records…
GridFieldConfig_RelationEditor
The final option is the Relation Edition set up. This adds features to work with ‘has-many’ and ‘many-many’ relationships.
See our article about Many_Many relations for more details
Custom Config
Or, you can just create an empty configuration, and add the bits you need….
1 2 3 4 5 6 7 8 9 10 |
$gridFieldConfig =GridFieldConfig::create()->addComponents( newGridFieldToolbarHeader(), newGridFieldAddNewButton('toolbar-header-right'), newGridFieldSortableHeader(), newGridFieldDataColumns(), newGridFieldPaginator(15), newGridFieldEditButton(), newGridFieldDeleteAction(), newGridFieldDetailForm(),newGridFieldFilterHeader(), ); |