Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Custom sort of DataObjects

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: 738 Views
  • theGermaniac
    Community Member
    82 Posts

    Custom sort of DataObjects Link to this post

    Hey there!

    How can I custom sort DataObjects - means how to sort them independent from it's columns. This was possible with the DataObject Manager Module in SS 2.x and it was great!

    Thanks. Mario

  • Matty Balaam
    Community Member
    69 Posts

    Re: Custom sort of DataObjects Link to this post

    I think it's going to be introduced to the core at a later date, but at the moment you need to install this module:


  • DesignerX.com.au
    Community Member
    107 Posts

    Re: Custom sort of DataObjects Link to this post

    That module works great .. It took me sometime to get it working so here few things that may save you alot of time :
    Example for a basic Gallery module = Gallery has_many GalleryImages
    ** GalleryImage.php
    - Make sure you add field for SortID
    Code to use :
    // to change the default sorting to the new SortID
    public static $default_sort = 'SortID Asc';
    // To change the Default Value if SortID to LastSortID+1 , basic auto sort
    function onBeforeWrite() {
    if (!$this->SortID) {
    return $this->SortID = $this->getNextSortID();

    public function getNextSortID() {
    return $this->SGallery()->Images()->Last()->SortID + 1;

    ** Gallery.php
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $gridFieldConfig = GridFieldConfig_RelationEditor::create();
    new GridFieldSortableRows("SortID")

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.