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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Ordering $summary_fields


Go to End


4 Posts   2669 Views

Avatar
Jin

Community Member, 2 Posts

2 November 2009 at 12:49am

suppose I have:

static $summary_fields = array(
'Name',
'ProductCode'
);

I want to order the search results, for one " order by Name DESC", where can I specify the order?

Thanks,
Jin

Avatar
Willr

Forum Moderator, 5523 Posts

2 November 2009 at 9:59am

You can specify a $default_sort on your dataobject to set how it sorts itself.

// on your dataobject
static $default_sort = "Name DESC";

Note this is a global setting so any other <% controls %> or dataobject sets relating to that dataobject type will be sorted in that way.

Avatar
timwjohn

Community Member, 98 Posts

18 March 2010 at 9:10am

How about ordering by a linked DataObject?

For example I have set $summary_fields to include "Sector.Name", referring to a has_one relationship with the Sector DataObject.

default_sort = "Sector.Name ASC" is throwing an error - as I'd expected. How could I fix this?

Avatar
timwjohn

Community Member, 98 Posts

19 March 2010 at 4:06am

I've noticed the option to sort that field in the search results table isn't available.

I've tried adding it to "Sector.Name" to $search_fields but that's not doing anything.

Bit rusty on the SQL front, but I assume the query is selecting Sector.Name, otherwise it wouldn't be able to search or retrieve it, am I right? So am I just using the wrong $default_sort argument?

Thank you for your time!