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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?

Go to End

4 Posts   1126 Views


Community Member, 89 Posts

21 November 2011 at 5:48pm

Edited: 21/11/2011 5:48pm


I have a long list of non-hiearchical DataObjects, and need to have a picker for that to use in the CMS. Long list loaded on page load is out of question, it is not navigable enough, and it needs to fit in the sidebar of the CMS.

My first line of thinking was to make a fake hierarchy and inject it into TreeDropdownField. For example an alphabetic buckets would be great - sort objects by Titles starting from a, b, c and so on. That would speed up the loading, and I could further break down the list into smaller sections if need be, e.g. Aa-Ac.

Any ideas?


Forum Moderator, 1899 Posts

21 November 2011 at 11:10pm

how about...
this will allow searching and ordering like a CTF within a div popup to find a record quickly.


Community Member, 89 Posts

22 November 2011 at 10:30am

Good try, thank you. But I don't have an underlying object, nor relationship, so HasOneItemSetField will not do. SearchItemSetField is undocumented, and what I see it's doing is just displaying a read-only list of pre-filtered items. Also not useful here.

I have a list of DataObjects, and need a form control to pick one. It should not assume that there is a HasOne under it. For example DropdownField can be either used in relational context or without it. Any other ideas? :)



Community Member, 89 Posts

22 November 2011 at 1:55pm

Got it.

I have used smindel's DataObejctPicker field with some interface modifications to make it a bit smoother: . This field allows user to type a keyword, and provides suggestions which can be chosen. They populate an invisible field which can then be submitted normally to form handler.

$picker = new DataObjectPicker('PrWrapperID', 'P&R Wrapper');
$picker->setConfig('completeFunction', array('PrWrapper', 'pickerSuggestion'));

The callback accepts a SS_HTTPRequest, and returns an json array of arrays with line items.

	static function pickerSuggestion($req) {
		$request = Convert::raw2sql($req->requestVar('request'));
		$results = DataObject::get('PrWrapper', "\"Title\" ILIKE '%$request%' OR \"Summary\" ILIKE '%$request%'", "\"ReleaseDate\" DESC");

		$json = array(
				'id' => '0',
				'title' => '-- none selected --',
				'full' => "-- select none --",
				'style' => 'color:red',

		if ($results) {
			foreach ($results as $result) {
				$json[] = array(
					'id' => $result->ID,
					'title' => Convert::raw2att($result->obj('Title')->LimitCharacters(30)),
					'full' => Convert::raw2att("$result->Title [".$result->Type()->Name."]")
		return json_encode($json);


Attached Files