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.

Customising the CMS /

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

Change the text of Dropdown field in ModelAdmin Filter

Go to End

2 Posts   910 Views


Community Member, 37 Posts

12 March 2014 at 5:43pm

Silverstripe 3.1.3

Hoping this is a simple one but I have some dataobjects being managed through ModelAdmin. One of the fields is simply a day name field which is being stored as an Enum field with options 1 - 7.

In the filter on the left hand side the dropdown shows the values 1 - 7, but I would like it to read 'Monday, Tuesday etc'. How do I change this?

I only have the field storing it as a number as I want to be able to sort in the correct week order, so open to any better ways of doing this.

public static $db = array (
			'Day' => 'Enum("1,2,3,4,5,6,7")',


public static $summary_fields = array(
			'Term.Title' => 'Term',
			'DayName' => 'Day',
			'Course.Title' => 'Class',
			'StartTime' => 'Start',
			'EndTime' => 'End',
			'Studio' => 'Studio'
private static $searchable_fields = array(
	  'Instructor.Name' => 'PartialMatchFilter',
	  'Term.Title' => 'PartialMatchFilter',
	  'Course.Title' => 'PartialMatchFilter'

public function DayName(){
		$day_number = $this->Day;
			case 1:
			$day = 'Monday';
			case 2:
			$day = 'Tuesday';
			case 3:
			$day = 'Wednesday';
			case 4:
			$day = 'Thursday';
			case 5:
			$day = 'Friday';
			case 6:
			$day = 'Saturday';
			case 7:
			$day = 'Sunday';
		return $day;


Community Member, 20 Posts

14 March 2014 at 11:48pm

Edited: 15/03/2014 6:31am

Hi Vix

As it happens I had a very similar problem a few months back
The trick here is very simple, if a little counter-intuitive

First: do not specify Day in the $searchable_fields array, as this will build its dropdown list from the enum vaules

Second: insert the Day dropdown your self in your ModelAdmin class
You will need to overload getSearchContext() and getList()

Refer to the model admin docs for more info (

In getSearchContext() you insert the dropdown field into the search form -- this works exactly like adding a field in getCMSFields() or on a custom form
You can then specify your own selection list
Hint: DropdownField expects the selection list as an associative array -- e.g. array(1 => 'Monday', 2=>'Tuesday', 3 => 'Wednesday', etc)

Then use getList() to amend the list of selected items for the display grid

One point, the docs imply that in getList() you specify the selection like this:
$list->filter('Day' => $params['Day']);
This does not work (and it cost me a couple of hours worth of head scratching and searching the API docs to work out why)

The filter method does not alter the the existing list, it returns a new filtered list, so use:
$list = $list->filter('Day' => $params['Day']);

Hope that helps
Mike Armstrong
(Silvertoad Ltd)