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, biapar, Willr, Ingo, swaiba

many_many sortable GridField in SS3


Go to End
Reply


604 Views

Avatar
lozhowlett

Community Member, 151 Posts

25 October 2012 at 1:58am

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 :(