How can I change the default collation for members in Silverstripe?

By default, the Member object looks like this:

private static $default_sort = '"Surname", "FirstName"';

      

We have a project where I want to sort all members under "Security" in CMS "LastEdited DESC".

I tried to apply it using DataExtension:

class ClubMemberFields extends DataExtension {

  private static $default_sort = 'LastEdited DESC'; 

...
}

      

YML:

Member:
  extensions:
    - 'ClubMemberFields'

      

Even after / dev / build / members are still sorted by last name / first name. What do I need to do to set $ default_sort to LastEdited?

+3


source to share


1 answer


as on silverstripe 3, the new config system is installed.
this new config system also handles things like $ db and $ default_sort etc.

you are already using this config system in two ways: using private static $default_sort

and yml config files.

what a lot of people don't know is that they are the same configuration. So you can set default_sort

in yml:

Member:
  default_sort: 'LastEdited DESC'

      



This should overwrite the value from private static $default_sort

.
Because the hierarchy for the config system is: Config::inst()->update()

> yml> php private static

other than using yml is easier in this case, I don't see anything wrong with your DataExtension, maybe you can't overwrite default_sort with this, I don't know.
If the yml version doesn't work as well, it is possible that the list you see is not using the default collation, but instead applying its own collation.
in this case, you need to customize the list, not the member.

Edit: @Tama pointed out in a comment that the field can be part of summary_fields in order to work in a GridField.

+4


source







All Articles