Silverstripe Grid field extensions issue


#1

I’m trying to customise the fields that appear in the GridFieldEditableColumns component of the gridfieldextensions addon.

I think I’ve followed the code correctly from the github readme, but I keep getting an error “Call to a member function setDisplayFields() on null”

	public function getCMSFields()
    {
      $fields = parent::getCMSFields();

      $fields->addFieldToTab('Root.Main', TextField::create('Title', 'Title'));

      $config = GridFieldConfig::create()
	    ->addComponent(new GridFieldButtonRow('before'))
	    ->addComponent(new GridFieldToolbarHeader())
	    ->addComponent(new GridFieldTitleHeader())
	    ->addComponent(new GridFieldEditableColumns())
	    ->addComponent(new GridFieldDeleteAction())
	    ->addComponent(new GridFieldAddNewInlineButton());
	
	$grid = new GridField(
    	'MenuItems',
    	'Menu Items',
    	$this->MenuItems(),
    	$config
    );



    $grid->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFields([
		'Title' => function($record, $column, $grid) {
			return TextField::create($column);
		},
		'Link' => function($record, $column, $grid) {
			return TextField::create($column);
		}

	]);

    $fields->addFieldToTab('Root.Main', $grid); 

    return $fields;
}

Can anyone explain why this is happening?


#2

Can you confirm the version of SilverStripe you’re using?
If it’s SS4, you may need to use the fully qualified class name

eg. ->getComponentByType(GridFieldEditableColumns::class)


#3

You, sir, are a genius

Thank you