Note: The latest version of SS3 works differently to this article describes. Please check out this article for more up to date info, or check the silverstripe.com help files
Silverstripe 3 - beta 2 - More About Grid Fields
With SS3 Beta 2 just release, the upcoming release of the CMS is getting close now.
We're now able to add pages, images, members quite nicely. But the big thing is that the grid field system seems to be working properly. And importantly, we can now 'add' new items to the grid list.
Using a GridField with getCMSFields
function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
$gridfield = new GridField("GalleryItems", "My Gallery Items", $this->GalleryItems(), $gridFieldConfig);
$fields->addFieldToTab('Root.GalleryItems', $gridfield);
return $fields;
}