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 =newGridField("RegisterEvents","RegisterEvent", $this->RegisterEvents());
$fields->addFieldToTab('Root.Events', $gridfield);

grid1

$gridfield = new GridField(“RegisterEvents”, “RegisterEvent”, $this->RegisterEvents());
$fields->addFieldToTab(‘Root.Events’, $gridfield);

GridFieldConfig_RecordViewer

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

grid2

GridFieldConfig_RecordEditor

$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…

grid3

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(
newGridFieldToolbarHeader(),
newGridFieldAddNewButton('toolbar-header-right'),
newGridFieldSortableHeader(),
newGridFieldDataColumns(),
newGridFieldPaginator(15),
newGridFieldEditButton(),
newGridFieldDeleteAction(),
newGridFieldDetailForm(),newGridFieldFilterHeader(),
);

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *