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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Sorting DOM objects on the front end

Go to End

4 Posts   1442 Views


Community Member, 103 Posts

21 October 2010 at 8:54am

I built a FDOM like so:

$manager = new FileDataObjectManager(
            $this, // Controller
            'Resources', // Source name
            'Resource', // Source class
            'Attachment', // File name on DataObject
                'Name' => 'Name', 
            ), // Headings 
            'getCMSFields_forPopup', // Detail fields (function name or FieldSet object)
            '',// Filter clause
            'Name ASC'// Sort clause
            // Join clause

The data objects are always sorted as I'd like in the CMS, but how do I get them to display the same way in the template?
                    <% control Resources %>
                        <tr class="$EvenOdd">
                            <td class="left">$Name</td>
                            <td><a href="$Attachment.URL" target="_blank">Download</a></td>
                    <% end_control %>


Forum Moderator, 4102 Posts

21 October 2010 at 9:01am

You can add a $default_sort property to your Resource object..

static $default_sort = "Title ASC";

SilverStripe tips, tutorials, screencasts and more:


Community Member, 103 Posts

21 October 2010 at 9:53am

Perfect. Thank you for the fast response (and your overall dedication to the SS community)!


Community Member, 16 Posts

15 March 2011 at 6:09am

What if you are trying to sort by the "Attachment" instead of "Title". Since Attachment is part of the $has_one array instead of the $db array, it has no actual entry, but rather is represented by the "AttachmentID" field. How do I go about sorting by the actual attachment name?

class Resource extends DataObject
	static $db = array (
		'Name' => 'Text',
		'Description' => 'Text'


	static $has_one = array (
		'Attachment' => 'File',
		'ReportPage' => 'ReportPage'
	static $default_sort = "AttachmentID ASC"; // Doesn't actually sort by Attachment name
	public function getCMSFields_forPopup()
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			new FileIFrameField('Attachment')