21278 Posts in 5728 Topics by 2599 members
General Questions
SilverStripe Forums » General Questions » SS3: SortableGridFieldComponent only sorts when allow drag and drop selected
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 126 Views |
-
SS3: SortableGridFieldComponent only sorts when allow drag and drop selected

20 February 2013 at 1:50am
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
<?phpclass 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();
}
} -
Re: SS3: SortableGridFieldComponent only sorts when allow drag and drop selected

20 February 2013 at 4:56am Last edited: 20 February 2013 4:56am
Hi Marijn
Make sure you set your $default_sort on your DataObject like so:
public static $default_sort='SortOrder';
Regards
-
Re: SS3: SortableGridFieldComponent only sorts when allow drag and drop selected

20 February 2013 at 6:24am
Hi Ioti,
Thanks, I knew it would be something simple that I missed!
Cheers,
Marijn.
| 126 Views | ||
|
Page:
1
|
Go to Top |


