Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SS3: SortableGridFieldComponent only sorts when allow drag and drop selected

Go to End

3 Posts   785 Views


Community Member, 176 Posts

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

class Thumbnail extends DataObject {
	public static $db = array(
		'Name' => 'Text',
		'Caption' => 'Text',

  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();


Community Member, 189 Posts

20 February 2013 at 4:56am

Edited: 20/02/2013 4:56am

Hi Marijn

Make sure you set your $default_sort on your DataObject like so:

public static $default_sort='SortOrder';



Community Member, 176 Posts

20 February 2013 at 6:24am

Hi Ioti,

Thanks, I knew it would be something simple that I missed!