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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Sorting CMSFields

Go to End

3 Posts   733 Views


Community Member, 96 Posts

5 February 2014 at 1:42am

Hey guys,

in my modeladmin (SS3.1) I have many different fields: normal TextFields, UploadFields, GridFields, many_many_extraFields, DropdownFields mapped with has_one-Relations.

The problem is that my interface looks a little bit messy. First normal TextFields are displayed, than the UploadField, than the GridField, etc...
Anyway it make no difference what position the single fields have in my code.

Any idea, how I can sort the fields without using jQuery?


Community Member, 187 Posts

5 February 2014 at 5:29am

Hi Bereusei,

The fields are ordered in whichever order you add them to the FieldList. For example:

$fields = new FieldList();
$fieldA = new TextField('Foo', 'Foo');
$fieldB = new TextField('Bar', 'Bar');


This will result in 'Field B' being added before 'Field A'.

If you're not creating the fields yourself, and are allowing the form scaffolder to create them for you, you can re-order them with:

$fields = parent::getCMSFields();
return $fields;



Community Member, 96 Posts

6 February 2014 at 4:10am

Edited: 06/02/2014 4:11am

Thanks kinglozzer. It works nice on regular fields.
Any idea how this would work on many_many_extrafields?

class ProductPage extends DataObject{

       static $many_many = array(
		'Products' => 'Product'

	public static $many_many_extraFields = array(
                 'Products' => array('Position' => 'Varchar(255)')
         public function getCMSFields(){
		$fields = parent::getCMSFields();

                $productFields = singleton('Product')->getCMSFields();
                $productFields->addFieldToTab('Root.Main', DropdownField::create('ManyMany[Position]', 'Position on page', array("top", "bottom")));
		$gridfieldConfig = GridFieldConfig_RelationEditor::create();

                $fields->addFieldsToTab("Root.Main", array(
        	$gridfield = GridField::create("Products", "Product", $this->Products(), $gridfieldConfig)

class Product extends DataObject{

I have the bad feeling, that this doesn´t work anyway, does it?