Jump to:

23355 Posts in 17734 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » many_many sortable GridField in SS3

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: 385 Views
  • lozhowlett
    Avatar
    Community Member
    144 Posts

    many_many sortable GridField in SS3 Link to this post

    Hi everyone

    I am trying to use sortable (drag and drop) on a dataobject. I have SS3 installed with the SortableGridField module. In the documentation it says...

    "For many_many relationships you must add a $many_many_extraFields static to the data object defining the relationship, see the SilverStripe documentation for more information on this. If you are using a many_many relationship you will need to do a custom getter to set the sort order of this relationship for use on the front end..."

    However I cant find any example of this in practise, has anyone done this yet?

    This is in "Page.php"

    $gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
    new GridFieldDeleteAction('unlinkrelation')
    );
    $gridfield = new GridField("RightCallToActions", "RightCallToAction", $this->RightCallToActions(), $gridFieldConfig);
    //$gridfield->addComponent(new GridFieldSortableRows('{Column to store sort}'));
    $fields->addFieldToTab('Root.RhsCTA', $gridfield);

    Relationship is

    public static $many_many = array(
    'LowerCallToActions' => 'LowerCallToAction',
    'RightCallToActions' => 'RightCallToAction'
    );

    public static $belongs_many_many = array(
    'Pages' => 'Page'
    );

    In SS2.4.x i used: SortableDataObject::add_sortable_class('HotelImage'); which was super simple! Shame its not the same and you now have to add sortable bits yourself

    385 Views
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.