21309 Posts in 5738 Topics by 2603 members
General Questions
SilverStripe Forums » General Questions » Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 289 Views |
-
Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?

21 November 2011 at 5:48pm Last edited: 21 November 2011 5:48pm
Hey,
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?
mat -
Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?

21 November 2011 at 11:10pm
how about... https://github.com/ajshort/silverstripe-itemsetfield?
this will allow searching and ordering like a CTF within a div popup to find a record quickly. -
Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?

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?
mat
-
Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions?

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: https://github.com/mateusz/silverstripe-dataobjectpicker/ . 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(
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);
}Thanks!
Mateusz
| 289 Views | ||
|
Page:
1
|
Go to Top |

