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.

Customising the CMS /

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

SS3 the method 'setdisplayfields' does not exist on 'GridField'


Go to End


4 Posts   2842 Views

Avatar
Thomashv

Community Member, 35 Posts

17 July 2012 at 9:56pm

Edited: 17/07/2012 9:57pm

Hi,

I have problems with the setdisplayfields method in SilverStripe 3.0.0. It says that the method 'setdisplayfields' does not exist on 'GridField'. Is there anybody else that has experiend similar problems? I post my code here and hope some of you have an idea of what I'm doing wrong here...


class HomePage extends Page {
	public static $db = array(
	
	);
	
	public static $has_many = array(
		'HomePageSlides' => 'HomePageSlide' // link the slide items
	);
		
	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("HomePageSlides", "Slides", $this->HomePageSlides(), $gridfieldConfig);
		
		 $gridfield->setDisplayFields(array(
		 	'ID' => 'ID'
		 	));
		
		$fields->addFieldToTab('Root.Slides', $gridfield);
		 
		return $fields;
  	}
}

class HomePage_Controller extends Page_Controller {

	public static $allowed_actions = array (
	);

	public function init() {
		parent::init();
	}
}

Avatar
James Bolitho

Community Member, 33 Posts

17 July 2012 at 10:32pm

Hi Thomashv,

I was having the same issue with 'setFieldCasting'. It looks like the documentation on this needs to be updated because it seems that this has to be implemented differently now. I looked at the AssetAdmin.php in the cms/code/controllers/ folder for inspiration.

I would try this and see if it works:


$gridfield = new GridField("HomePageSlides", "Slides", $this->HomePageSlides(), $gridfieldConfig); 

$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');  //new line that needs to be added to your code

$columns->setDisplayFields(array(  //change $gridfield in your code to $columns
          'ID' => 'ID'
          )); 

Hope that helps.

Cheers,

Jim

Avatar
dpde

Community Member, 15 Posts

18 July 2012 at 9:07pm

You can use the variable $summary_fields in your DataObject or something like this:

$gridColumns = new GridFieldDataColumns();
    $gridColumns->setDisplayFields(array(
      'ID' => 'ID',
      'Title' => 'Titel'
    ));
    
    $gridFieldConfig = GridFieldConfig::create()->addComponents(
      new GridFieldToolbarHeader(),
      new GridFieldAddNewButton('toolbar-header-right'),
      new GridFieldSortableHeader(),
      //new GridFieldDataColumns(),
      new GridFieldPaginator(10),
      new GridFieldEditButton(),
      new GridFieldDeleteAction(),
      new GridFieldDetailForm()
      $gridColumns
    );

Avatar
Martin D.

Community Member, 21 Posts

27 August 2013 at 12:07pm

$summary_fields doesn't seems to be working but Jim's solution does.

$columns = $listField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array(
    'Name' => 'Name',
    'Prices' => 'Prices' 
));

'setDisplayFields' is a method of GridFieldDataColumns, not the GridField itself.