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?