I'm trying to sort a GridField in SS3. Installed the module SortableGridFieldComponent, which only sorts when 'Allow drag and drop' is selected, as soon as the checkbox is unchecked or the page is saved the sort order reverts to the order they dataobjects where created in. Anyone any ideas?
// HomePage
class HomePage extends Page {
static function isLocalhost() {
return Utils::isLocalHost();
}
public static $has_one = array(
);
public static $has_many = array(
"Thumbnails" => "Thumbnail",
);
function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig_RecordEditor::create()->addComponents(new GridFieldDeleteAction('unlinkrelation'));
$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$gridField = new GridField("Thumbnails", "Thumbnails", $this->Thumbnails(), $gridFieldConfig);
$fields->addFieldToTab("Root.Thumbnails", $gridField);
return $fields;
}
}
// Thumbnails
<?php
class Thumbnail extends DataObject {
public static $db = array(
'Name' => 'Text',
'Caption' => 'Text',
'SortOrder'=>'Int'
);
public static $has_one = array(
"Image" => "Image",
"HomePage" => "HomePage",
"LinkedPage" => "Page"
);
// Summary fields
public static $summary_fields = array(
'Thumbnail' => 'Thumbnail',
'Name' => 'Name',
'Caption' => 'Caption'
);
public function getThumbnail() {
return $this->Image()->CMSThumbnail();
}
}