Sorting Groups in CMS SS3.6

I have a lot of Groups in the CMS, most of them are within a parent Group, but I noticed that they are sorted by ID and not sorted alphabetically or by the sort field. How do I correct this?

It might be enough to add a default_sort setting to your Group model. For example:

$default_sort = '"Sort" ASC';

or

$default_sort = '"Title" ASC';

You can also chain sort fields to use in case of duplicate values

$default_sort = '"Title" ASC, "LastEdited" DESC';

If you’re talking about the SilverStripe\Security\Group model you can’t directly edit the static vars but you can set the sort through yaml config:

# SilverStripe 4.x
SilverStripe\Security\Group
  default_sort: '"Title" ASC'

# SilverStripe 3.x
Group
  default_sort: '"Title" ASC'

Thank you! Yes I am talking about the SilverStripe\Security\Group. I tried this but did not get it to work. Where exactly do I put the yaml config code?

Thanks so much for your help.

Sorry I didn’t notice this was a SilverStripe 3.x question. Try removing the namespace prefix (SilverStripe\Security\ ) from the example and place it in one of your projects’ config files, e.g. mysite/_config/config.yml then do a flush.

That worked, thank you so much!

1 Like

Glad it helped you! I edited my original reply to include SS3 example and marked it as the solution for future readers.