Magento 2 dynamicRows as new tab for admin customer edit, how do you get data loaded?Magento 2 add new tab in...

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

Do I have an "anti-research" personality?

how to sum variables from file in bash

How to get a plain text file version of a CP/M .BAS (M-BASIC) program?

How much cash can I safely carry into the USA and avoid civil forfeiture?

Apply MapThread to all but one variable

Don’t seats that recline flat defeat the purpose of having seatbelts?

Why do Computer Science majors learn Calculus?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Packing rectangles: Does rotation ever help?

Will a top journal at least read my introduction?

How to pronounce 'C++' in Spanish

Unexpected email from Yorkshire Bank

What are the potential pitfalls when using metals as a currency?

How to have a sharp product image?

Is the 5 MB static resource size limit 5,242,880 bytes or 5,000,000 bytes?

What's the polite way to say "I need to urinate"?

How could Tony Stark make this in Endgame?

How to type a section sign (§) into the Minecraft client

A Strange Latex Symbol

Pulling the rope with one hand is as heavy as with two hands?

simple conditions equation

Noun clause (singular all the time?)

Was there a Viking Exchange as well as a Columbian one?



Magento 2 dynamicRows as new tab for admin customer edit, how do you get data loaded?


Magento 2 add new tab in customer dashboard frontendNew Tab in Admin Product Edit in Custom ModuleMagento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formMagento 2. Customer Edit TabGet customer data in Additional template file in customer account editMagento2 REST API get all customers detailsHow To Add Custom Data Into Product Edit Form DynamicRows Ui ComponentMagento 2 custom tab on customer section in admin panelHow to remove/hide a tab in customer admin edit in magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















How can I load the data from customer DataProvider plugin into my ui_component dynamicRows?



I have created a new tab in the admin customer edit form, and added my ui_component, which seems to work well. But I can't populate the data already stored in my database.



I have tried to add xml for DataSource, but I think that has conflict with original customer_form.xml DataSource "customer_form.customer_form_data_source" because when I add DataSource, the page no longer loads.



dataSource XML:



<dataSource name="mycustomrows">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">MyVendorMyModuleModelCustomerDataProvider</argument>
<argument name="primaryFieldName" xsi:type="string">id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="meta" xsi:type="array">
<item name="mycustomrows" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">My Custom Rows</item>
</item>
</item>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
</item>
</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</dataSource>


dataProvider for dataSource:



<?php

namespace MyVendorMyModuleModelCustomer;

class DataProvider extends MagentoUiDataProviderAbstractDataProvider
{
protected $loadedData;
protected $collectionFactory;

public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
MyVendorMyModuleModelResourceModelRowCollection $collection,
MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
array $meta = [],
array $data = []
) {
$this->collection = $collection;
$this->collectionFactory = $collectionFactory;

parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}

public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}

$collection = $this->collectionFactory->create();
// add Filter for Customer ID
//->setOrder('position', 'ASC');
$items = $collection->getItems();

foreach ($items as $item) {
$this->loadedData[$item->getId()] = $item->getData();
}

return $this->loadedData;
}
}


I believe the data has to be loaded with Plugin for "MagentoCustomerModelCustomerDataProvider" as I am doing below, but I can't seem to get populate rows on load.



view/adminhtml/ui_component/customer_form.xml



<?xml version="1.0" encoding="UTF-8"?>

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="mycustomrows">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">My Custom Rows</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<dynamicRows name="mycustomrows">
<settings>
<addButtonLabel translate="true">Add Row</addButtonLabel>
<additionalClasses>
<class name="admin__field-wide">true</class>
</additionalClasses>
<componentType>dynamicRows</componentType>
</settings>

<container name="record" component="Magento_Ui/js/dynamic-rows/record">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="isTemplate" xsi:type="boolean">true</item>
<item name="is_collection" xsi:type="boolean">true</item>
<item name="componentType" xsi:type="string">container</item>
<item name="positionProvider" xsi:type="string">position</item>
</item>
</argument>


<field name="mycustomrows_select1" formElement="select" sortOrder="10">
<settings>
<dataType>text</dataType>
<label translate="true">Select Field 1</label>
<disabled>false</disabled>
<dataScope>mycustomrows_select1</dataScope>
</settings>
<formElements>
<select>
<settings>
<options class="MyVendorMyModuleModelSourceSelectFieldOne"/>
</settings>
</select>
</formElements>
</field>
<field name="mycustomrows_input1" sortOrder="20" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">customer</item>
</item>
</argument>
<settings>
<label translate="true">Text Field 1</label>
<dataType>text</dataType>
<dataScope>mycustomrows_text1</dataScope>
</settings>
</field>
<actionDelete sortOrder="30">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentType" xsi:type="string">actionDelete</item>
<item name="dataType" xsi:type="string">text</item>
<item name="fit" xsi:type="boolean">false</item>
<item name="label" xsi:type="string">Actions</item>
<item name="sortOrder" xsi:type="string">500</item>
<item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
<item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
</item>
</argument>
</actionDelete>
</container>
</dynamicRows>
</fieldset>
</form>


etc/adminhtml/di.xml



<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerModelCustomerDataProvider">
<plugin name="customer_get_mycustomrows" type="MyVendorMyModuleModelCustomerDataProvider" sortOrder="5" />
</type>
</config>


Model/Customer/DataProvider.php



<?php
namespace MyVendorMyModuleModelCustomer;

class DataProvider
{
protected $collection;
protected $collectionFactory;
protected $loadedData;

public function __construct(
MyVendorMyModuleModelResourceModelRowCollection $collection,
MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
array $data = []
) {
$this->collection = $collection;
$this->collectionFactory = $collectionFactory;
}

public function afterGetData(MagentoCustomerModelCustomerDataProvider $subject, $result)
{
if($result){
$customer_id = key($result);
$customerData = $result[$customer_id]['customer'];

if(is_null($this->loadedData)) {
$this->loadedData = array();
$collection = $this->collectionFactory->create(); //->setOrder('position', 'ASC');
$items = $collection->getItems();

foreach ($items as $item) {
$this->loadedData[] = $item->getData();
}
}

$result[$customer_id]['customer']["mycustomrows"] = $this->loadedData;
}
return $result;
}

}


I can't seem to get any records populated when I load a customer edit page.










share|improve this question







New contributor




Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    How can I load the data from customer DataProvider plugin into my ui_component dynamicRows?



    I have created a new tab in the admin customer edit form, and added my ui_component, which seems to work well. But I can't populate the data already stored in my database.



    I have tried to add xml for DataSource, but I think that has conflict with original customer_form.xml DataSource "customer_form.customer_form_data_source" because when I add DataSource, the page no longer loads.



    dataSource XML:



    <dataSource name="mycustomrows">
    <argument name="dataProvider" xsi:type="configurableObject">
    <argument name="class" xsi:type="string">MyVendorMyModuleModelCustomerDataProvider</argument>
    <argument name="primaryFieldName" xsi:type="string">id</argument>
    <argument name="requestFieldName" xsi:type="string">id</argument>
    <argument name="meta" xsi:type="array">
    <item name="mycustomrows" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
    </item>
    </item>
    </argument>
    <argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
    </item>
    </argument>
    </argument>
    <argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
    </item>
    </argument>
    </dataSource>


    dataProvider for dataSource:



    <?php

    namespace MyVendorMyModuleModelCustomer;

    class DataProvider extends MagentoUiDataProviderAbstractDataProvider
    {
    protected $loadedData;
    protected $collectionFactory;

    public function __construct(
    $name,
    $primaryFieldName,
    $requestFieldName,
    MyVendorMyModuleModelResourceModelRowCollection $collection,
    MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
    array $meta = [],
    array $data = []
    ) {
    $this->collection = $collection;
    $this->collectionFactory = $collectionFactory;

    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
    }

    public function getData()
    {
    if (isset($this->loadedData)) {
    return $this->loadedData;
    }

    $collection = $this->collectionFactory->create();
    // add Filter for Customer ID
    //->setOrder('position', 'ASC');
    $items = $collection->getItems();

    foreach ($items as $item) {
    $this->loadedData[$item->getId()] = $item->getData();
    }

    return $this->loadedData;
    }
    }


    I believe the data has to be loaded with Plugin for "MagentoCustomerModelCustomerDataProvider" as I am doing below, but I can't seem to get populate rows on load.



    view/adminhtml/ui_component/customer_form.xml



    <?xml version="1.0" encoding="UTF-8"?>

    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="mycustomrows">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
    <item name="sortOrder" xsi:type="number">10</item>
    </item>
    </argument>
    <dynamicRows name="mycustomrows">
    <settings>
    <addButtonLabel translate="true">Add Row</addButtonLabel>
    <additionalClasses>
    <class name="admin__field-wide">true</class>
    </additionalClasses>
    <componentType>dynamicRows</componentType>
    </settings>

    <container name="record" component="Magento_Ui/js/dynamic-rows/record">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="isTemplate" xsi:type="boolean">true</item>
    <item name="is_collection" xsi:type="boolean">true</item>
    <item name="componentType" xsi:type="string">container</item>
    <item name="positionProvider" xsi:type="string">position</item>
    </item>
    </argument>


    <field name="mycustomrows_select1" formElement="select" sortOrder="10">
    <settings>
    <dataType>text</dataType>
    <label translate="true">Select Field 1</label>
    <disabled>false</disabled>
    <dataScope>mycustomrows_select1</dataScope>
    </settings>
    <formElements>
    <select>
    <settings>
    <options class="MyVendorMyModuleModelSourceSelectFieldOne"/>
    </settings>
    </select>
    </formElements>
    </field>
    <field name="mycustomrows_input1" sortOrder="20" formElement="input">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="source" xsi:type="string">customer</item>
    </item>
    </argument>
    <settings>
    <label translate="true">Text Field 1</label>
    <dataType>text</dataType>
    <dataScope>mycustomrows_text1</dataScope>
    </settings>
    </field>
    <actionDelete sortOrder="30">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="componentType" xsi:type="string">actionDelete</item>
    <item name="dataType" xsi:type="string">text</item>
    <item name="fit" xsi:type="boolean">false</item>
    <item name="label" xsi:type="string">Actions</item>
    <item name="sortOrder" xsi:type="string">500</item>
    <item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
    <item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
    </item>
    </argument>
    </actionDelete>
    </container>
    </dynamicRows>
    </fieldset>
    </form>


    etc/adminhtml/di.xml



    <?xml version="1.0"?>

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCustomerModelCustomerDataProvider">
    <plugin name="customer_get_mycustomrows" type="MyVendorMyModuleModelCustomerDataProvider" sortOrder="5" />
    </type>
    </config>


    Model/Customer/DataProvider.php



    <?php
    namespace MyVendorMyModuleModelCustomer;

    class DataProvider
    {
    protected $collection;
    protected $collectionFactory;
    protected $loadedData;

    public function __construct(
    MyVendorMyModuleModelResourceModelRowCollection $collection,
    MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
    array $data = []
    ) {
    $this->collection = $collection;
    $this->collectionFactory = $collectionFactory;
    }

    public function afterGetData(MagentoCustomerModelCustomerDataProvider $subject, $result)
    {
    if($result){
    $customer_id = key($result);
    $customerData = $result[$customer_id]['customer'];

    if(is_null($this->loadedData)) {
    $this->loadedData = array();
    $collection = $this->collectionFactory->create(); //->setOrder('position', 'ASC');
    $items = $collection->getItems();

    foreach ($items as $item) {
    $this->loadedData[] = $item->getData();
    }
    }

    $result[$customer_id]['customer']["mycustomrows"] = $this->loadedData;
    }
    return $result;
    }

    }


    I can't seem to get any records populated when I load a customer edit page.










    share|improve this question







    New contributor




    Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      How can I load the data from customer DataProvider plugin into my ui_component dynamicRows?



      I have created a new tab in the admin customer edit form, and added my ui_component, which seems to work well. But I can't populate the data already stored in my database.



      I have tried to add xml for DataSource, but I think that has conflict with original customer_form.xml DataSource "customer_form.customer_form_data_source" because when I add DataSource, the page no longer loads.



      dataSource XML:



      <dataSource name="mycustomrows">
      <argument name="dataProvider" xsi:type="configurableObject">
      <argument name="class" xsi:type="string">MyVendorMyModuleModelCustomerDataProvider</argument>
      <argument name="primaryFieldName" xsi:type="string">id</argument>
      <argument name="requestFieldName" xsi:type="string">id</argument>
      <argument name="meta" xsi:type="array">
      <item name="mycustomrows" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
      </item>
      </item>
      </argument>
      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
      </item>
      </argument>
      </argument>
      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
      </item>
      </argument>
      </dataSource>


      dataProvider for dataSource:



      <?php

      namespace MyVendorMyModuleModelCustomer;

      class DataProvider extends MagentoUiDataProviderAbstractDataProvider
      {
      protected $loadedData;
      protected $collectionFactory;

      public function __construct(
      $name,
      $primaryFieldName,
      $requestFieldName,
      MyVendorMyModuleModelResourceModelRowCollection $collection,
      MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
      array $meta = [],
      array $data = []
      ) {
      $this->collection = $collection;
      $this->collectionFactory = $collectionFactory;

      parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
      }

      public function getData()
      {
      if (isset($this->loadedData)) {
      return $this->loadedData;
      }

      $collection = $this->collectionFactory->create();
      // add Filter for Customer ID
      //->setOrder('position', 'ASC');
      $items = $collection->getItems();

      foreach ($items as $item) {
      $this->loadedData[$item->getId()] = $item->getData();
      }

      return $this->loadedData;
      }
      }


      I believe the data has to be loaded with Plugin for "MagentoCustomerModelCustomerDataProvider" as I am doing below, but I can't seem to get populate rows on load.



      view/adminhtml/ui_component/customer_form.xml



      <?xml version="1.0" encoding="UTF-8"?>

      <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <fieldset name="mycustomrows">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
      <item name="sortOrder" xsi:type="number">10</item>
      </item>
      </argument>
      <dynamicRows name="mycustomrows">
      <settings>
      <addButtonLabel translate="true">Add Row</addButtonLabel>
      <additionalClasses>
      <class name="admin__field-wide">true</class>
      </additionalClasses>
      <componentType>dynamicRows</componentType>
      </settings>

      <container name="record" component="Magento_Ui/js/dynamic-rows/record">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="isTemplate" xsi:type="boolean">true</item>
      <item name="is_collection" xsi:type="boolean">true</item>
      <item name="componentType" xsi:type="string">container</item>
      <item name="positionProvider" xsi:type="string">position</item>
      </item>
      </argument>


      <field name="mycustomrows_select1" formElement="select" sortOrder="10">
      <settings>
      <dataType>text</dataType>
      <label translate="true">Select Field 1</label>
      <disabled>false</disabled>
      <dataScope>mycustomrows_select1</dataScope>
      </settings>
      <formElements>
      <select>
      <settings>
      <options class="MyVendorMyModuleModelSourceSelectFieldOne"/>
      </settings>
      </select>
      </formElements>
      </field>
      <field name="mycustomrows_input1" sortOrder="20" formElement="input">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="source" xsi:type="string">customer</item>
      </item>
      </argument>
      <settings>
      <label translate="true">Text Field 1</label>
      <dataType>text</dataType>
      <dataScope>mycustomrows_text1</dataScope>
      </settings>
      </field>
      <actionDelete sortOrder="30">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="componentType" xsi:type="string">actionDelete</item>
      <item name="dataType" xsi:type="string">text</item>
      <item name="fit" xsi:type="boolean">false</item>
      <item name="label" xsi:type="string">Actions</item>
      <item name="sortOrder" xsi:type="string">500</item>
      <item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
      <item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
      </item>
      </argument>
      </actionDelete>
      </container>
      </dynamicRows>
      </fieldset>
      </form>


      etc/adminhtml/di.xml



      <?xml version="1.0"?>

      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCustomerModelCustomerDataProvider">
      <plugin name="customer_get_mycustomrows" type="MyVendorMyModuleModelCustomerDataProvider" sortOrder="5" />
      </type>
      </config>


      Model/Customer/DataProvider.php



      <?php
      namespace MyVendorMyModuleModelCustomer;

      class DataProvider
      {
      protected $collection;
      protected $collectionFactory;
      protected $loadedData;

      public function __construct(
      MyVendorMyModuleModelResourceModelRowCollection $collection,
      MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
      array $data = []
      ) {
      $this->collection = $collection;
      $this->collectionFactory = $collectionFactory;
      }

      public function afterGetData(MagentoCustomerModelCustomerDataProvider $subject, $result)
      {
      if($result){
      $customer_id = key($result);
      $customerData = $result[$customer_id]['customer'];

      if(is_null($this->loadedData)) {
      $this->loadedData = array();
      $collection = $this->collectionFactory->create(); //->setOrder('position', 'ASC');
      $items = $collection->getItems();

      foreach ($items as $item) {
      $this->loadedData[] = $item->getData();
      }
      }

      $result[$customer_id]['customer']["mycustomrows"] = $this->loadedData;
      }
      return $result;
      }

      }


      I can't seem to get any records populated when I load a customer edit page.










      share|improve this question







      New contributor




      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      How can I load the data from customer DataProvider plugin into my ui_component dynamicRows?



      I have created a new tab in the admin customer edit form, and added my ui_component, which seems to work well. But I can't populate the data already stored in my database.



      I have tried to add xml for DataSource, but I think that has conflict with original customer_form.xml DataSource "customer_form.customer_form_data_source" because when I add DataSource, the page no longer loads.



      dataSource XML:



      <dataSource name="mycustomrows">
      <argument name="dataProvider" xsi:type="configurableObject">
      <argument name="class" xsi:type="string">MyVendorMyModuleModelCustomerDataProvider</argument>
      <argument name="primaryFieldName" xsi:type="string">id</argument>
      <argument name="requestFieldName" xsi:type="string">id</argument>
      <argument name="meta" xsi:type="array">
      <item name="mycustomrows" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
      </item>
      </item>
      </argument>
      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
      </item>
      </argument>
      </argument>
      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
      </item>
      </argument>
      </dataSource>


      dataProvider for dataSource:



      <?php

      namespace MyVendorMyModuleModelCustomer;

      class DataProvider extends MagentoUiDataProviderAbstractDataProvider
      {
      protected $loadedData;
      protected $collectionFactory;

      public function __construct(
      $name,
      $primaryFieldName,
      $requestFieldName,
      MyVendorMyModuleModelResourceModelRowCollection $collection,
      MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
      array $meta = [],
      array $data = []
      ) {
      $this->collection = $collection;
      $this->collectionFactory = $collectionFactory;

      parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
      }

      public function getData()
      {
      if (isset($this->loadedData)) {
      return $this->loadedData;
      }

      $collection = $this->collectionFactory->create();
      // add Filter for Customer ID
      //->setOrder('position', 'ASC');
      $items = $collection->getItems();

      foreach ($items as $item) {
      $this->loadedData[$item->getId()] = $item->getData();
      }

      return $this->loadedData;
      }
      }


      I believe the data has to be loaded with Plugin for "MagentoCustomerModelCustomerDataProvider" as I am doing below, but I can't seem to get populate rows on load.



      view/adminhtml/ui_component/customer_form.xml



      <?xml version="1.0" encoding="UTF-8"?>

      <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
      <fieldset name="mycustomrows">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">My Custom Rows</item>
      <item name="sortOrder" xsi:type="number">10</item>
      </item>
      </argument>
      <dynamicRows name="mycustomrows">
      <settings>
      <addButtonLabel translate="true">Add Row</addButtonLabel>
      <additionalClasses>
      <class name="admin__field-wide">true</class>
      </additionalClasses>
      <componentType>dynamicRows</componentType>
      </settings>

      <container name="record" component="Magento_Ui/js/dynamic-rows/record">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="isTemplate" xsi:type="boolean">true</item>
      <item name="is_collection" xsi:type="boolean">true</item>
      <item name="componentType" xsi:type="string">container</item>
      <item name="positionProvider" xsi:type="string">position</item>
      </item>
      </argument>


      <field name="mycustomrows_select1" formElement="select" sortOrder="10">
      <settings>
      <dataType>text</dataType>
      <label translate="true">Select Field 1</label>
      <disabled>false</disabled>
      <dataScope>mycustomrows_select1</dataScope>
      </settings>
      <formElements>
      <select>
      <settings>
      <options class="MyVendorMyModuleModelSourceSelectFieldOne"/>
      </settings>
      </select>
      </formElements>
      </field>
      <field name="mycustomrows_input1" sortOrder="20" formElement="input">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="source" xsi:type="string">customer</item>
      </item>
      </argument>
      <settings>
      <label translate="true">Text Field 1</label>
      <dataType>text</dataType>
      <dataScope>mycustomrows_text1</dataScope>
      </settings>
      </field>
      <actionDelete sortOrder="30">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="componentType" xsi:type="string">actionDelete</item>
      <item name="dataType" xsi:type="string">text</item>
      <item name="fit" xsi:type="boolean">false</item>
      <item name="label" xsi:type="string">Actions</item>
      <item name="sortOrder" xsi:type="string">500</item>
      <item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
      <item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
      </item>
      </argument>
      </actionDelete>
      </container>
      </dynamicRows>
      </fieldset>
      </form>


      etc/adminhtml/di.xml



      <?xml version="1.0"?>

      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoCustomerModelCustomerDataProvider">
      <plugin name="customer_get_mycustomrows" type="MyVendorMyModuleModelCustomerDataProvider" sortOrder="5" />
      </type>
      </config>


      Model/Customer/DataProvider.php



      <?php
      namespace MyVendorMyModuleModelCustomer;

      class DataProvider
      {
      protected $collection;
      protected $collectionFactory;
      protected $loadedData;

      public function __construct(
      MyVendorMyModuleModelResourceModelRowCollection $collection,
      MyVendorMyModuleModelResourceModelRowCollectionFactory $collectionFactory,
      array $data = []
      ) {
      $this->collection = $collection;
      $this->collectionFactory = $collectionFactory;
      }

      public function afterGetData(MagentoCustomerModelCustomerDataProvider $subject, $result)
      {
      if($result){
      $customer_id = key($result);
      $customerData = $result[$customer_id]['customer'];

      if(is_null($this->loadedData)) {
      $this->loadedData = array();
      $collection = $this->collectionFactory->create(); //->setOrder('position', 'ASC');
      $items = $collection->getItems();

      foreach ($items as $item) {
      $this->loadedData[] = $item->getData();
      }
      }

      $result[$customer_id]['customer']["mycustomrows"] = $this->loadedData;
      }
      return $result;
      }

      }


      I can't seem to get any records populated when I load a customer edit page.







      magento2 customer-account dynamic-rows






      share|improve this question







      New contributor




      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 16 mins ago









      Cmaclean066Cmaclean066

      11




      11




      New contributor




      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Cmaclean066 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Cmaclean066 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272700%2fmagento-2-dynamicrows-as-new-tab-for-admin-customer-edit-how-do-you-get-data-lo%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Cmaclean066 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Cmaclean066 is a new contributor. Be nice, and check out our Code of Conduct.













          Cmaclean066 is a new contributor. Be nice, and check out our Code of Conduct.












          Cmaclean066 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f272700%2fmagento-2-dynamicrows-as-new-tab-for-admin-customer-edit-how-do-you-get-data-lo%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...