Jump to:

23380 Posts in 18311 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Drag and drop reordering of SS3 Grid Field

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: 3250 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    Drag and drop reordering of SS3 Grid Field Link to this post

    I seem to be very good at creating ghost town posts on this forum but thought I'd have one last attempt.

    There is very minimal documentation out there on SS3 Grid Fields at the moment. I am looking for a way to achieve drag and drop (or another method) reordering of the items in a Grid Field. Using the dataobjectmanager in SS2.4 I just had to add SortableDataObject::add_sortable_class('Classname') to my config file and hey presto, I could order the items.

    Does anyone know how I can achieve this with Grid Fields in SS3?

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    Hey Fraser

    There's a Sortable Grid Field module that provides a component for allowing drag and drop reordering of GridField objects. You just need to provide a sort field.

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    Perfect.

    Thanks Simon.

  • LuiLoop
    Avatar
    Community Member
    2 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    Hi,

    i have installed this plugin but i dont have an idea how i can use this module.

    I try it on an example from the official tutorial (http://doc.silverstripe.com/framework/en/tutorials/5-dataobject-relationship-management) but it doesnt work.

    Where i can find a usable tutorial?

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    Hi LuiLoop. Setting up the SortableGridField is pretty easy. Here's an example

    In your DataObject class, you need to first create a column to sort by. I usually use something simple like SortID.

    class MyDataObject extends DataObject {
    public static $db=array(
    'SortID'=>'Int'
    );
    }

    then where you're setting up your gridfield, add the SortableGridFieldComponent.

    class Page extends SiteTree {

    public static $has_many=array(
    'MyDataObjects'=>'MyDataObject'
    );

    public function getCMSFields(){
    $fields=parent::getCMSFields();

    $fields->addFieldToTab('Root.Main',
    GridField::create('MyDataObjects', 'Data Object',
    $this->MyDataObjects(),
    GridFieldConfig_RecordEditor::create()
    ->addComponent(new GridFieldSortableRows('SortID')) //use addComponent() function to add SortableGridFieldRows
    )
    );

    return $fields;
    }
    }

    hope that helps!

  • LuiLoop
    Avatar
    Community Member
    2 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    thx, now it works

    But i have a litle second question. How i can create a DropDownField in my Gridfield - i cant find any documentation

  • datswicked
    Avatar
    Community Member
    15 Posts

    Re: Drag and drop reordering of SS3 Grid Field Link to this post

    Hi LuiLoop,

    thanks for this post was very helpfull just now... with the dropdown list, i discovered i could use an Enum data type.
    worked for what i needed, let me know if that works for you or if you find another way..

    static $db = array(
    'Name' => 'Varchar(255)',
          'Title' => 'Varchar(255)',
          'Visible' => "Enum('Yes, No')",
           'SortID'=>'Int',
    );

    3250 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.