I'm trying to add drag and drop sorting to a GridField Relation Editor. It's a bookshop and on the homepage they just want to choose a few books from the collection to display:
(It's working perfectly without SortableGridField, but doesn't have drag and drop sorting obviously).
I have it set-up like so:
public static $many_many = array(
'HomeBooks' => 'Book',
);
public static $many_many_extraFields=array(
'HomeBooks'=>array(
'SortOrder'=>'Int'
)
);
At the moment I have my grid field set-up like this and it's working fine (without GridFieldSortableRows)
$gridFieldConfig2 = GridFieldConfig_RelationEditor::create();
$gridFieldConfig2->removeComponentsByType('GridFieldAddNewButton');
$gridFieldConfig2->removeComponentsByType('GridFieldEditButton');
$gridFieldConfig2->removeComponentsByType('GridFieldSortableHeader');
$gridFieldConfig2->removeComponentsByType('GridFieldFilterHeader');
$gridfield2 = new GridField("HomeBooks", "Featured Books", $this->HomeBooks()->sort("ID DESC"), $gridFieldConfig2);
$fields->addFieldToTab('Root.FeaturedTitles', $gridfield2);
But when I change it to this I get an Internal Server Error on the page:
$gridFieldConfig2 = GridFieldConfig_RelationEditor::create();
$gridFieldConfig2->addComponent(new GridFieldSortableRows('SortOrder'));
$gridFieldConfig2->removeComponentsByType('GridFieldAddNewButton');
$gridFieldConfig2->removeComponentsByType('GridFieldEditButton');
$gridFieldConfig2->removeComponentsByType('GridFieldSortableHeader');
$gridFieldConfig2->removeComponentsByType('GridFieldFilterHeader');
$gridfield2 = new GridField("HomeBooks", "Featured Books", $this->HomeBooks()->sort('SortOrder'), $gridFieldConfig2);
$fields->addFieldToTab('Root.FeaturedTitles', $gridfield2);
Any help would be greatly appreciated.