Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Resolved] Alphabetizing/Sorting A Data List

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

Page: 1
Go to End
Author Topic: 1566 Views
  • jfusco
    Avatar
    Community Member
    52 Posts

    [Resolved] Alphabetizing/Sorting A Data List Link to this post

    Hello,

    I have looked in the SS documentation and located the syntax for the DataObject::Get query:

    $records = DataObject::get($obj, $filter, $sort, $join, $limit);


    My question is, what are the valid arguments for $sort? If I want to alphabetize my query results, what value needs to be in that parameter?

    Sorry if this is a noob question, my eyes are tired from looking at the web and my brain can't figure out how to phrase my searches anymore.

    Thanks in advance,
    Joe

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: [Resolved] Alphabetizing/Sorting A Data List Link to this post

    The $sort param is exactly the same as your SQL ORDER clause (without the actualy ORDER BY part). To sort alphabetically, you just do something like "`MyField` DESC"

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: [Resolved] Alphabetizing/Sorting A Data List Link to this post

    I'm hanging my head in embarrassed shame but I have very little idea what you just said. I'm not familiar with the SQL ORDER clause. Are you saying I need to put "DESC" in place of $Sort in the expression?

    Thanks

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: [Resolved] Alphabetizing/Sorting A Data List Link to this post

    Alright, I figured out I could put "Title DESC" into the $Sort parameter and it sorts... from Z to A. How do I reverse the sort?

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: [Resolved] Alphabetizing/Sorting A Data List Link to this post

    You can use ASC/DESC to change the order.

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: [Resolved] Alphabetizing/Sorting A Data List Link to this post

    Yep, just figured that out. Actually, I just removed the DESC qualifier (which I originally thought meant DESCription, not DESCending - FACEPALM -).

    D'OH!!

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