7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Sorting DOM objects on the front end
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 766 Views |
-
Sorting DOM objects on the front end

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
array(
'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?
template:<table>
<thead>
<tr>
<th>Name</th>
<th>Link</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<% control Resources %>
<tr class="$EvenOdd">
<td class="left">$Name</td>
<td><a href="$Attachment.URL" target="_blank">Download</a></td>
<td>$Attachment.Size</td>
</tr>
<% end_control %>
</tbody>
</table> -
Re: Sorting DOM objects on the front end

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: http://www.leftandmain.com -
Re: Sorting DOM objects on the front end

21 October 2010 at 9:53am
Perfect. Thank you for the fast response (and your overall dedication to the SS community)!
-
Re: Sorting DOM objects on the front end

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')
);
}
}
| 766 Views | ||
|
Page:
1
|
Go to Top |

