Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Display order in "Files & Images"

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1041 Views
  • Xurk
    Avatar
    Community Member
    50 Posts

    Display order in "Files & Images" Link to this post

    For clarification: We're running SilverStripe 2.4.0 for a client with DataObjectManager (version from around the end of May, 2010).

    In the back-end, the client would like to have the uploaded files lists to be sorted by the upload date, descending - i.e. the most recently uploaded image to be located at the top of the list. The default setting is the reverse order.

    I've been searching through the boards and trying to hunt down the template / class responsible for displaying the right-hand side of the "Files & Images" part of SilverStripe ("admin/assets/") but haven't had any luck.

    Could anyone point me in the right direction? I assume that the solution would be something along the lines of editing the initialization of a DataObjectManager object in the right class.

  • CraftsMan
    Avatar
    Community Member
    35 Posts

    Re: Display order in "Files & Images" Link to this post

    Did you manage to find a solution for this? I have the same need.

    By default it allows for drag and drop re-ordering so it might be a requirement to disable this to a custom sort order be allowed.

  • Xurk
    Avatar
    Community Member
    50 Posts

    Re: Display order in "Files & Images" Link to this post

    Sorry, we weren't able to find any solution for this. So we've put it on the back-burner. If you manage to find anything that works, we'd love to hear it

  • chrclaus
    Avatar
    Community Member
    29 Posts

    Re: Display order in "Files & Images" Link to this post

    Hello,

    I´m not sure if this tip meets your problem, but I had problems with the sortorder in the DataObjectManager too. Every $sourceSort I specified in the constructor was not used anyway.
    The problem is the function loadSort() in DataObjectManager

       protected function loadSort()
       {
          if($this->ShowAll())
             $this->setPageSize(999);
          
          if($this->Sortable() && (!isset($_REQUEST['ctf'][$this->Name()]['sort']) || $_REQUEST['ctf'][$this->Name()]['sort'] == "SortOrder")) {
             $this->sort = "SortOrder";
             $this->sourceSort = "SortOrder ASC";
          }
          elseif(isset($_REQUEST['ctf'][$this->Name()]['sort']) && !empty($_REQUEST['ctf'][$this->Name()]['sort'])) {
             $this->sourceSort = $_REQUEST['ctf'][$this->Name()]['sort'] . " " . $this->sort_dir;
          }
          else {
             $this->sourceSort = singleton($this->sourceClass())->stat('default_sort');
          }

       }


    which overwrites the variable $sourcesort in every case. Setting the static variable $default_sort in the current DataObject

    /**
        * The default sort expression. This will be inserted in the ORDER BY
        * clause of a SQL query if no other sort expression is provided.
        * @var string
        */
       public static $default_sort = 'StartDate';


    as stated in the else-part solved my problem.

    Best regards,
    chrclaus

  • Xurk
    Avatar
    Community Member
    50 Posts

    Re: Display order in "Files & Images" Link to this post

    Thanks for your response, chrclaus The reason why I haven't posted sooner is because I still haven't gotten around to trying your solution out yet... but it does seem plausible so I'll give it a shot when it's called for again!

    However, I noticed that the official SilverStripe Twitter account retweeted a blog post on this subject yesterday, so I thought I'd post that solution here for others who stumble upon this thread.

    https://twitter.com/#!/silverstripe/statuses/55397559417569280

    In case the blog post ever goes down, this is what it basically comes down to:
    Again, add this to your mysite/_config.php file:

    SortableDataObject::$sortable_classes = array();

    and then move your existing SortableDataObject::add_sortable_classes declaration below it, if you did already have one. This will not only make the table now sort in the default_sort, but will remove the useful features of dataobject_manager from the table, so I'd generally advise not to do this; I'm simply showing that it can be done.

    So this solution does have drawbacks, but it also gets the job done. Chrclaus' solution might be better though ;)

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