title: Magento 2: Add customer in grid on category edit page at admin panel
body: <p>As in the product page we can add related product with modal, I want to add the special customer to the grid table in the category page.I list,show customers in modal,i can select but when I add the customer, it does not add to the grid table.</p>
  
  <pre><code>public function modifyMeta(array $meta)
      {
          $meta = array_replace_recursive(
              $meta,
              [
                  static::GROUP_CUSTOMERTAB =&gt; [
                      'children' =&gt; [
                          $this-&gt;scopePrefix . static::DATA_SCOPE_CUSTOMER =&gt; $this-&gt;getCustomerFieldset(),
                      ],
                      'arguments' =&gt; [
                          'data' =&gt; [
                              'config' =&gt; [
                                  'label' =&gt; __('Customer'),
                                  'collapsible' =&gt; true,
                                  'componentType' =&gt; Fieldset::NAME,
                                  'dataScope' =&gt; static::DATA_SCOPE,
                                  'sortOrder' =&gt; $this-&gt;getNextGroupSortOrder(
                                      $meta,
                                      self::$previousGroup,
                                      self::$sortOrder
                                  ),
  
                              ],
                          ],
  
                      ],
                  ],
              ]
          );
  
          return $meta;
      }  
  
  
  
  
      protected function getCustomerFieldset()
      {
  
          $content = __(
              'This products are shown to customers in addition to the item the customer is looking at.'
          );
  
          return [
              'children' =&gt; [
                  'button_set' =&gt; $this-&gt;getButtonSet(
                      $content,
                      __('Add Specific Customer'),
                      $this-&gt;scopePrefix . static::DATA_SCOPE_CUSTOMER
                  ),
                  'modal' =&gt; $this-&gt;getGenericModal(
                      __('Add Specific Customer'),
                      $this-&gt;scopePrefix . static::DATA_SCOPE_CUSTOMER
                  ),
                  static::DATA_SCOPE_CUSTOMER =&gt; $this-&gt;getGrid($this-&gt;scopePrefix . static::DATA_SCOPE_CUSTOMER),
              ],
              'arguments' =&gt; [
                  'data' =&gt; [
                      'config' =&gt; [
                          'additionalClasses' =&gt; 'admin__fieldset-section',
                          'label' =&gt; __('Customer'),
                          'collapsible' =&gt; false,
                          'componentType' =&gt; Fieldset::NAME,
                          'dataScope' =&gt; '',
                          'sortOrder' =&gt; 100,
                      ],
                  ],
              ]
          ];
      }
  
  
      /**
       * Retrieve button set
       *
       * @param Phrase $content
       * @param Phrase $buttonTitle
       * @param string $scope
       * @return array
       */
      protected function getButtonSet(Phrase $content, Phrase $buttonTitle, $scope)
      {
  
          $modalTarget = $this-&gt;scopeName . '.' . static::GROUP_CUSTOMERTAB . '.' . $scope . '.modal';
  
  
          return [
              'arguments' =&gt; [
                  'data' =&gt; [
                      'config' =&gt; [
                          'formElement' =&gt; 'container',
                          'componentType' =&gt; 'container',
                          'label' =&gt; false,
                          'content' =&gt; $content,
                          'template' =&gt; 'ui/form/components/complex',
                      ],
                  ],
              ],
              'children' =&gt; [
                  'button_' . $scope =&gt; [
                      'arguments' =&gt; [
                          'data' =&gt; [
                              'config' =&gt; [
                                  'formElement' =&gt; 'container',
                                  'componentType' =&gt; 'container',
                                  'component' =&gt; 'Magento_Ui/js/form/components/button',
                                  'actions' =&gt; [
                                      [
                                          'targetName' =&gt; $modalTarget,
                                          'actionName' =&gt; 'toggleModal',
                                      ],
                                      [
                                          'targetName' =&gt; $modalTarget . '.' . $scope . '_customer_listing',
                                          'actionName' =&gt; 'render',
                                      ]
                                  ],
                                  'title' =&gt; $buttonTitle,
                                  'provider' =&gt; null,
                              ],
                          ],
                      ],
  
                  ],
              ],
          ];
      }
  
      /**
       * Prepares config for modal slide-out panel
       *
       * @param Phrase $title
       * @param string $scope
       * @return array
       */
      protected function getGenericModal(Phrase $title, $scope)
      {
  
  
          $listingTarget = $scope . '_customer_listing';
  
  
          $modal = [
              'arguments' =&gt; [
                  'data' =&gt; [
                      'config' =&gt; [
                          'componentType' =&gt; Modal::NAME,
                          'dataScope' =&gt; '',
                          'options' =&gt; [
                              'title' =&gt; $title,
                              'buttons' =&gt; [
                                  [
                                      'text' =&gt; __('Cancel'),
                                      'actions' =&gt; [
                                          'closeModal'
                                      ]
                                  ],
                                  [
                                      'text' =&gt; __('Add Selected Customers'),
                                      'class' =&gt; 'action-primary test',
                                      'id' =&gt; 'submit',
                                      'actions' =&gt; [
                                          [
                                              'targetName' =&gt; 'index = ' . $listingTarget,
                                              'actionName' =&gt; 'save'
                                          ],
                                          'closeModal'
                                      ]
                                  ],
                              ],
                          ],
                      ],
                  ],
              ],
              'children' =&gt; [
                  $listingTarget =&gt; [
                      'arguments' =&gt; [
                          'data' =&gt; [
                              'config' =&gt; [
                                  'autoRender' =&gt; false,
                                  'componentType' =&gt; 'insertListing',
                                  'dataScope' =&gt; $listingTarget,
                                  'externalProvider' =&gt; $listingTarget . '.' . $listingTarget . '_data_source',
                                  'selectionsProvider' =&gt; $listingTarget . '.' . $listingTarget . '.customer_columns.ids',
                                  'ns' =&gt; $listingTarget,
                                  'render_url' =&gt; $this-&gt;urlBuilder-&gt;getUrl('mui/index/render'),
                                  'realTimeLink' =&gt; true,
                                  'dataLinks' =&gt; [
                                      'imports' =&gt; false,
                                      'exports' =&gt; true
                                  ],
                                  'behaviourType' =&gt; 'simple',
                                  'externalFilterMode' =&gt; true,
                                  'imports' =&gt; [
                                      'productId' =&gt; '${ $.provider }:data.category.current_category_id',
                                      'storeId' =&gt; '${ $.provider }:data.category.current_store_id',
                                  ],
                                  'exports' =&gt; [
                                      'productId' =&gt; '${ $.externalProvider }:params.current_category_id',
                                      'storeId' =&gt; '${ $.externalProvider }:params.current_store_id',
                                  ]
                              ],
                          ],
                      ],
                  ],
              ],
          ];
  
          return $modal;
      }
  
      /**
       * Retrieve grid
       *
       * @param string $scope
       * @return array
       * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
       */
      protected function getGrid($scope)
      {
          $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/diacore.log');
          $logger = new \Zend\Log\Logger();
          $logger-&gt;addWriter($writer);
  
          $dataProvider = $scope . '_customer_listing';
           $getGrid = [
              'arguments' =&gt; [
                  'data' =&gt; [
                      'config' =&gt; [
                          'additionalClasses' =&gt; 'admin__field-wide',
                          'componentType' =&gt; DynamicRows::NAME,
                          'label' =&gt; null,
                          'columnsHeader' =&gt; true,
                          'columnsHeaderAfterRender' =&gt; true,
                          'renderDefaultRecord' =&gt; true,
                          'template' =&gt; 'ui/dynamic-rows/templates/grid',
                          'component' =&gt; 'Magento_Ui/js/dynamic-rows/dynamic-rows-grid',
                          'addButton' =&gt; false,
                          'recordTemplate' =&gt; 'record',
                          'dataScope' =&gt; 'data.links',
                          'deleteButtonLabel' =&gt; __('Remove'),
                          'dataProvider' =&gt; $dataProvider ,
                          'map' =&gt; [
                              'id' =&gt; 'entity_id',
                              'name' =&gt; 'name',
                              'email' =&gt; 'email',
                          ],
                          'links' =&gt; [
                              'insertData' =&gt; '${ $.provider }:${ $.dataProvider }'
                          ],
                          'sortOrder' =&gt; 2,
                      ],
                  ],
              ],
              'children' =&gt; [
                  'record' =&gt; [
                      'arguments' =&gt; [
                          'data' =&gt; [
                              'config' =&gt; [
                                  'componentType' =&gt; 'container',
                                  'isTemplate' =&gt; true,
                                  'is_collection' =&gt; true,
                                  'component' =&gt; 'Magento_Ui/js/dynamic-rows/record',
                                  'dataScope' =&gt; '',
                              ],
                          ],
                      ],
                      'children' =&gt; $this-&gt;fillMeta(),
                  ],
              ],
          ];
  
          $logger-&gt;info($getGrid);
  
          return $getGrid;
      }
  
      /**
       * Retrieve meta column
       *
       * @return array
       */
      protected function fillMeta()
      {
          return [
              'id' =&gt; $this-&gt;getTextColumn('id', false, __('ID'), 0),
              'name' =&gt; $this-&gt;getTextColumn('name', false, __('Name'), 20),
              'email' =&gt; $this-&gt;getTextColumn('email', true, __('Email'), 30),
              'actionDelete' =&gt; [
                  'arguments' =&gt; [
                      'data' =&gt; [
                          'config' =&gt; [
                              'additionalClasses' =&gt; 'data-grid-actions-cell',
                              'componentType' =&gt; 'actionDelete',
                              'dataType' =&gt; Text::NAME,
                              'label' =&gt; __('Actions'),
                              'sortOrder' =&gt; 70,
                              'fit' =&gt; true,
                          ],
                      ],
                  ],
              ],
          ];
      }
  
      /**
       * Retrieve text column structure
       *
       * @param string $dataScope
       * @param bool $fit
       * @param Phrase $label
       * @param int $sortOrder
       * @return array
       */
      protected function getTextColumn($dataScope, $fit, Phrase $label, $sortOrder)
      {
          $column = [
              'arguments' =&gt; [
                  'data' =&gt; [
                      'config' =&gt; [
                          'componentType' =&gt; Field::NAME,
                          'formElement' =&gt; Input::NAME,
                          'elementTmpl' =&gt; 'ui/dynamic-rows/cells/text',
                          'component' =&gt; 'Magento_Ui/js/form/element/text',
                          'dataType' =&gt; Text::NAME,
                          'dataScope' =&gt; $dataScope,
                          'fit' =&gt; $fit,
                          'label' =&gt; $label,
                          'sortOrder' =&gt; $sortOrder,
                      ],
                  ],
              ],
          ];
  
          return $column;
      }
  </code></pre>
  
  <p>di.xml is that</p>
  
  <pre><code>&lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"&gt;
  
      &lt;type name="Vendor\Module\Ui\DataProvider\Product\Modifier\Customertab"&gt;
          &lt;arguments&gt;
              &lt;argument name="scopeName" xsi:type="string"&gt;category_form.category_form&lt;/argument&gt;
          &lt;/arguments&gt;
      &lt;/type&gt;
      &lt;type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"&gt;
          &lt;arguments&gt;
              &lt;argument name="collections" xsi:type="array"&gt;
                  &lt;item name="customertab_customer_listing_data_source" xsi:type="string"&gt;Magento\Customer\Model\ResourceModel\Grid\Collection&lt;/item&gt;
              &lt;/argument&gt;
          &lt;/arguments&gt;
      &lt;/type&gt;
  
  &lt;/config&gt;
  </code></pre>
  
  <p>view\admnihtml\ui_component\customertab_customer_listing.xml is that </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"&gt;
      &lt;argument name="data" xsi:type="array"&gt;
          &lt;item name="js_config" xsi:type="array"&gt;
  
              &lt;item name="provider" xsi:type="string"&gt;customertab_customer_listing.customertab_customer_listing_data_source&lt;/item&gt;
              &lt;item name="deps" xsi:type="string"&gt;customertab_customer_listing.customertab_customer_listing_data_source&lt;/item&gt;
          &lt;/item&gt;
          &lt;item name="spinner" xsi:type="string"&gt;customer_columns&lt;/item&gt;
      &lt;/argument&gt;
      &lt;dataSource name="customertab_customer_listing_data_source"&gt;
          &lt;argument name="dataProvider" xsi:type="configurableObject"&gt;
              &lt;argument name="class" xsi:type="string"&gt;Magento\Customer\Ui\Component\DataProvider&lt;/argument&gt;
              &lt;argument name="name" xsi:type="string"&gt;customertab_customer_listing_data_source&lt;/argument&gt;
              &lt;argument name="primaryFieldName" xsi:type="string"&gt;entity_id&lt;/argument&gt;
              &lt;argument name="requestFieldName" xsi:type="string"&gt;id&lt;/argument&gt;
              &lt;argument name="data" xsi:type="array"&gt;
                  &lt;item name="config" xsi:type="array"&gt;
                      &lt;item name="component" xsi:type="string"&gt;Magento_Ui/js/grid/provider&lt;/item&gt;
                      &lt;item name="update_url" xsi:type="url" path="mui/index/render"/&gt;
                      &lt;item name="storageConfig" xsi:type="array"&gt;
                          &lt;item name="cacheRequests" xsi:type="boolean"&gt;false&lt;/item&gt;
                      &lt;/item&gt;
                  &lt;/item&gt;
              &lt;/argument&gt;
          &lt;/argument&gt;
      &lt;/dataSource&gt;
      &lt;columns name="customer_columns" class="Magento\Customer\Ui\Component\Listing\Columns"&gt;
          &lt;argument name="data" xsi:type="array"&gt;
              &lt;item name="config" xsi:type="array"&gt;
                  &lt;item name="childDefaults" xsi:type="array"&gt;
                      &lt;item name="fieldAction" xsi:type="array"&gt;
                          &lt;item name="provider" xsi:type="string"&gt;customertab_customer_listing.customertab_customer_listing.customer_columns_editor&lt;/item&gt;
                          &lt;item name="target" xsi:type="string"&gt;selectCustomer&lt;/item&gt;
                          &lt;item name="params" xsi:type="array"&gt;
                              &lt;item name="0" xsi:type="string"&gt;${ $.$data.rowIndex }&lt;/item&gt;
                          &lt;/item&gt;
                      &lt;/item&gt;
                  &lt;/item&gt;
              &lt;/item&gt;
          &lt;/argument&gt;
          &lt;selectionsColumn name="ids"&gt;
              &lt;argument name="data" xsi:type="array"&gt;
                  &lt;item name="config" xsi:type="array"&gt;
                      &lt;item name="indexField" xsi:type="string"&gt;entity_id&lt;/item&gt;
                      &lt;item name="sortOrder" xsi:type="number"&gt;0&lt;/item&gt;
                      &lt;item name="preserveSelectionsOnFilter" xsi:type="boolean"&gt;true&lt;/item&gt;
                  &lt;/item&gt;
              &lt;/argument&gt;
          &lt;/selectionsColumn&gt;
          &lt;column name="entity_id"&gt;
              &lt;argument name="data" xsi:type="array"&gt;
                  &lt;item name="config" xsi:type="array"&gt;
                      &lt;item name="filter" xsi:type="string"&gt;textRange&lt;/item&gt;
                      &lt;item name="sorting" xsi:type="string"&gt;asc&lt;/item&gt;
                      &lt;item name="label" xsi:type="string" translate="true"&gt;ID&lt;/item&gt;
                      &lt;item name="sortOrder" xsi:type="number"&gt;10&lt;/item&gt;
                  &lt;/item&gt;
              &lt;/argument&gt;
          &lt;/column&gt;
          &lt;column name="name"&gt;
              &lt;argument name="data" xsi:type="array"&gt;
                  &lt;item name="config" xsi:type="array"&gt;
                      &lt;item name="filter" xsi:type="string"&gt;text&lt;/item&gt;
                      &lt;item name="label" xsi:type="string" translate="true"&gt;Name&lt;/item&gt;
                      &lt;item name="sortOrder" xsi:type="number"&gt;30&lt;/item&gt;
                  &lt;/item&gt;
              &lt;/argument&gt;
          &lt;/column&gt;
          &lt;column name="email"&gt;
              &lt;argument name="data" xsi:type="array"&gt;
                  &lt;item name="config" xsi:type="array"&gt;
                      &lt;item name="filter" xsi:type="string"&gt;text&lt;/item&gt;
                      &lt;item name="editor" xsi:type="string"&gt;text&lt;/item&gt;
                      &lt;item name="label" xsi:type="string" translate="true"&gt;Email&lt;/item&gt;
                      &lt;item name="sortOrder" xsi:type="number"&gt;40&lt;/item&gt;
                  &lt;/item&gt;
              &lt;/argument&gt;
          &lt;/column&gt;
      &lt;/columns&gt;
  &lt;/listing&gt;
  </code></pre>