diff --git a/docs/en/topics/grid-field.md b/docs/en/topics/grid-field.md index 790348c4a..7739c7627 100644 --- a/docs/en/topics/grid-field.md +++ b/docs/en/topics/grid-field.md @@ -51,7 +51,7 @@ If we wanted to make a simpler grid without pagination or filtering, we could do A `GridFieldConfig` is made up of a new of `GridFieldComponent` objects. `GridFieldComponent` is a family of interfaces. -## Build-in components +## Built-in components SilverStripe Framework comes with the following components that you can use out of the box. @@ -117,6 +117,18 @@ It's common for a component to implement several of these interfaces in order to * `GridField_ActionProvider`, to define the sortasc and sortdesc actions that add sort column and direction to the state. * `GridField_DataManipulator`, to alter the sorting of the data list based on the sort column and direction values in the state. + ### GridFieldRelationAdd + +A GridFieldRelationAdd is responsible for adding objects to another object's `has_many` and `many_many` relation, +as defined by the `[api:RelationList]` passed to the GridField constructor. +Objects can be searched through an input field (partially matching one or more fields). +Selecting from the results will add the object to the relation. + + :::php + $group = DataObject::get_one('Group'); + $config = GridFieldConfig::create()->addComponent(new GridFieldRelationAdd(array('FirstName', 'Surname', 'Email')); + $gridField = new GridField('Members', 'Members', $group->Members(), $config); + ## Component interfaces ### GridField_HTMLProvider diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index eae9ae5f2..55b3bf2a6 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -121,23 +121,21 @@ class GridFieldConfig_ManyManyEditor extends GridFieldConfig { /** * * @param string $fieldToSearch - Which field on the object should be searched for - * @param bool $autoSuggest - Show a jquery.ui.autosuggest dropdown field * @param int $itemsPerPage - How many items per page should show up * @return GridFieldConfig_ManyManyEditor */ - public static function create($fieldToSearch, $autoSuggest=true, $itemsPerPage=25){ - return new GridFieldConfig_ManyManyEditor($fieldToSearch, $autoSuggest=true, $itemsPerPage=25); + public static function create($fieldToSearch, $itemsPerPage=15){ + return new GridFieldConfig_ManyManyEditor($fieldToSearch, $itemsPerPage=15); } /** * * @param string $fieldToSearch - Which field on the object should be searched for - * @param bool $autoSuggest - Show a jquery.ui.autosuggest dropdown field * @param int $itemsPerPage - How many items per page should show up */ - public function __construct($fieldToSearch, $autoSuggest=true, $itemsPerPage=25) { + public function __construct($fieldToSearch, $itemsPerPage=15) { $this->addComponent(new GridFieldFilter()); - $this->addComponent(new GridFieldRelationAdd($fieldToSearch, $autoSuggest)); + $this->addComponent(new GridFieldRelationAdd($fieldToSearch)); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldDefaultColumns()); $this->addComponent(new GridFieldAction_Edit()); diff --git a/forms/gridfield/GridFieldRelationAdd.php b/forms/gridfield/GridFieldRelationAdd.php index d16f27d88..b656088f0 100755 --- a/forms/gridfield/GridFieldRelationAdd.php +++ b/forms/gridfield/GridFieldRelationAdd.php @@ -1,14 +1,9 @@ fieldToSearch = $fieldToSearch; - $this->useAutoSuggestion = $autoSuggestion; } /** @@ -52,13 +39,11 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr $searchState = $gridField->State->GridFieldSearchRelation; - if($this->useAutoSuggestion){ - Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); - Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); - Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); - Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); - Requirements::javascript(SAPPHIRE_DIR . "/javascript/GridFieldSearch.js"); - } + Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); + Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); + Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); + Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); + Requirements::javascript(SAPPHIRE_DIR . "/javascript/GridFieldSearch.js"); $forTemplate = new ArrayData(array()); $forTemplate->Fields = new ArrayList();