Jump to:

23553 Posts in 19380 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Sorting CMSFields

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

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

Page: 1
Go to End
Author Topic: 179 Views
  • Bereusei
    Community Member
    94 Posts

    Sorting CMSFields Link to this post

    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?

  • kinglozzer
    Community Member
    146 Posts

    Re: Sorting CMSFields Link to this post

    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;


  • Bereusei
    Community Member
    94 Posts

    Re: Sorting CMSFields Link to this post

    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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.