Silverstripe 3 Grid Field Config Options

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...

$gridfield = new GridField("RegisterEvents", "RegisterEvent", $this->RegisterEvents());
$fields->addFieldToTab('Root.Events', $gridfield);
$gridfield = new GridField("RegisterEvents", "RegisterEvent", $this->RegisterEvents());
$fields->addFieldToTab('Root.Events', $gridfield);

GridFieldConfig_RecordViewer

$gridFieldConfig = GridFieldConfig_RecordViewer::create();
$gridfield = new GridField("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

$gridFieldConfig = GridFieldConfig_RecordEditor::create();
$gridfield = new GridField("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....

$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm(), new GridFieldFilterHeader(),
);