Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin GridField not displaying in View context


Go to End


3 Posts   1079 Views

Avatar
Phill

Community Member, 81 Posts

22 September 2015 at 2:28am

Hi

I'm having an issue with GridFields not being displayed when viewing a record in model admin in the "view" context.

When i add a GridField to the object in getCmsFields using the following code, the field is displayed when opening the object in edit mode but when trying to open it in view made i just get the field name as a label with the value "(none)"

$fields->addFieldToTab('Root.Main',
GridField::create('Events', 'Events', Events::get()->limit(10))
);

Is there a way to have GridFields displayed when the item is opened in view mode?

Thanks

Avatar
Kirk

Community Member, 67 Posts

22 September 2015 at 11:35am

It sounds like you need to setup another method to override the edit form.
You call the method getEditForm and you can call the parent to get the standard form and you can then edit the form see below for a example

        public function getEditForm($id = null, $fields = null) {               
                $form = parent::getEditForm($id, $fields);                      
                                                                               
                // create your Events Gridfield
               // use $form->fields()->replaceField to replace the form field with your field            
                                                               
                                                                                
                return $form;                                                   
        } 

Avatar
Phill

Community Member, 81 Posts

26 September 2015 at 4:05am

Looks like the issue is caused after getEditForm() but a fix for this issue is here

https://github.com/silverstripe/silverstripe-blog/blob/master/code/extensions/BlogFilter.php#L84