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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Display order in "Files & Images"


Reply


5 Posts   1150 Views

Avatar
Xurk

Community Member, 50 Posts

3 November 2010 at 12:33am

Edited: 03/11/2010 12:33am

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.

Avatar
CraftsMan

Community Member, 35 Posts

11 February 2011 at 4:08am

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.

Avatar
Xurk

Community Member, 50 Posts

15 February 2011 at 3:05am

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

Avatar
chrclaus

Community Member, 29 Posts

23 February 2011 at 9:37am

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

Avatar
Xurk

Community Member, 50 Posts

6 April 2011 at 7:17pm

Edited: 06/04/2011 7:18pm

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.

[url]https://twitter.com/#!/silverstripe/statuses/55397559417569280[/url]

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 ;)