Jump to:

23552 Posts in 19349 Topics by 2891 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 523 Views
  • MateuszU
    Avatar
    Community Member
    89 Posts

    Need a picker field for a long list of non-hierarchical DataObjects - any suggestions? Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions? Link to this post

    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.

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions? Link to this post

    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

  • MateuszU
    Avatar
    Community Member
    89 Posts

    Re: Need a picker field for a long list of non-hierarchical DataObjects - any suggestions? Link to this post

    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

    Attached Files
    523 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.