setAppendToTop - Fatal error: Call to undefined method GridFieldSortableRows::create()
Closed this issue · 2 comments
claire-ee commented
I am trying to add setAppendToTop to my sortable GridField. However as soon as I add the following
$config->addComponent(GridFieldSortableRows::create('SortOrder')->setAppendToTop(true));
when I access page in the CMS I am getting:
Fatal error: Call to undefined method GridFieldSortableRows::create()
Silverstripe Version 3.1.2
Full code:
class ProductsHolderPage extends Page
{
private static $many_many = array(
'Products' => 'Product'
);
private static $many_many_extraFields=array(
'Products'=>array(
'SortOrder'=>'Int'
)
);
public function Products() {
return $this->getManyManyComponents('Products')->sort('SortOrder');
}
function getCMSFields()
{
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create(10);
$config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Name'))->setResultsFormat('$Name');
$config->addComponent(new GridFieldSortableRows('SortOrder'));
$config->addComponent(GridFieldSortableRows::create('SortOrder')->setAppendToTop(true));
$productsField = new GridField(
'Products',
'Product',
$this->Products()
,$config
);
$fields->addFieldsToTab('Root.Products', array(
$productsField
));
return $fields;
}
}
Many thanks
UndefinedOffset commented
This is because GridFieldSortableRows like most GridField components do not extend the Object class, so create() doesn't exist. You will need to do something like this instead:
$sortableRows=new GridFieldSortableRows('SortOrder');
$config->addComponent($sortableRows->setAppendToTop(true));
Also you probably shouldn't add it to the same GridField twice not sure what that would cause.
claire-ee commented
Thank you, that worked perfectly.
Claire