Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>there is a method called <code>setSearchList()</code> on <code>GridFieldAddExistingAutocompleter</code> with which you can set the list to be searched.</p> <p>however, I am not sure if that is fully implemented, but you should try the following:</p> <pre><code>// lets assume you want all Pages that have no parent (root pages) $listToBeSearched = Page::get()-&gt;filter('ParentID', 0); $autoCompleteField = new GridFieldAddExistingAutocompleter('toolbar-header-right'); $autoCompleteField-&gt;setSearchList($listToBeSearched); $config = GridFieldConfig::create()-&gt;addComponents( new GridFieldButtonRow('toolbar-header-right'), new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldDeleteAction(true), new GridFieldDetailForm(), $autoCompleteField ); </code></pre> <p>if you wish to filter by a function like in your question, then use <code>filterByCallback()</code> to filter the list:</p> <pre><code>// because GridFieldAddExistingAutocompleter only supports DataList at the moment // and filterByCallback() returns an ArrayList, we have to use a workaround // (which obviously yields a performance loss) $arrayList = Page::get()-&gt;filterByCallback(function($obj) { return $obj-&gt;isPublished(); }); // now that we have a list of pages that we want to search, // lets take the IDs of this list and create a DataList that filters for this IDs: $listToBeSearched = Page::get()-&gt;filter('ID', $arrayList-&gt;column('ID')); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload