Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Ordering $summary_fields

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

Page: 1
Go to End
Author Topic: 1697 Views
  • Jin
    Avatar
    Community Member
    2 Posts

    Ordering $summary_fields Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Ordering $summary_fields Link to this post

    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.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Ordering $summary_fields Link to this post

    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?

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Ordering $summary_fields Link to this post

    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!

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