1

In XML form I have fields: Name: Phone: Company: Company - dynamic rows

 <fieldset name="dynamic_rows_set">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Dynamic Rows</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
        <container name="dynamic_rows_container">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/dynamic-rows/dynamic-rows</item>
                    <item name="template" xsi:type="string">ui/dynamic-rows/templates/default</item>
                    <item name="componentType" xsi:type="string">dynamicRows</item>
                    <item name="recordTemplate" xsi:type="string">company</item>
                    <item name="addButtonLabel" xsi:type="string">Add slider</item>
                    <item name="deleteProperty" xsi:type="boolean">false</item>
                </item>
            </argument>
            <container name="company">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Sliders</item>
                        <item name="component" xsi:type="string" translate="true">Magento_Ui/js/dynamic-rows/record</item>
                        <item name="isTemplate" xsi:type="boolean">true</item>
                        <item name="is_collection" xsi:type="boolean">true</item>
                        <item name="showFallbackReset" xsi:type="boolean">false</item>
                    </item>
                </argument>
                <field name="company_name">
                    <argument name="data" xsi:type="array">
                        <item name="config" xsi:type="array">
                            <item name="dataType" xsi:type="string">text</item>
                            <item name="label" xsi:type="string" translate="true">Slider name</item>
                            <item name="formElement" xsi:type="string">input</item>
                            <item name="dataScope" xsi:type="string">slider_name</item>
                            <item name="showFallbackReset" xsi:type="boolean">false</item>
                            <item name="default" xsi:type="string">1</item>
                            <item name="validation" xsi:type="array">
                                <item name="required-entry" xsi:type="boolean">true</item>
                            </item>
                            <item name="sortOrder" xsi:type="string">10</item>
                        </item>
                    </argument>
                </field>

                <actionDelete>
                    <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="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>
        </container>
    </fieldset>

How I can do in dataprovider :

If(!$this->loadedData) 
{
   return default 10~ companies which I get in DB
}

ty!

3
  • share your data provider code. Commented May 15, 2019 at 7:06
  • @ChiragPatel codeshare.io/5RoDOj
    – Aaron
    Commented May 15, 2019 at 9:43
  • Hi, did you solve this? The answer only works for editing existing records Commented Jun 6, 2021 at 19:30

3 Answers 3

2

Use code below in DataProvider file:

if (null === $this->loadedData) {
    $this->loadedData[''] = [
        'database_field_name' => [
            [
                'field1' => 'field_value',
                'field2'  => 'field_value',
            ],
            [
                'field1' => 'field_value',
                'field2'  => 'field_value',
            ]
        ]
    ];
}

It worked for me.

1

Use code below in DataProvider file:

if (null === $this->loadedData) {
    $this->loadedData[''] = [
        'database_field_name' => [
            [
                'field1' => 'field_value',
                'field2'  => 'field_value',
            ],
            [
                'field1' => 'field_value',
                'field2'  => 'field_value',
            ]
        ]
    ];
}

It will worked.

0

Use below code in dataProvider file

$this->loadedData['id of your db row']['dynamic_rows_set']['company_name'] = 'company name value';

Note: must change id of your db row with your mysql table row

2
  • row table, or ? (I create new record, not edit)
    – Aaron
    Commented May 14, 2019 at 18:11
  • id of your edit record Commented May 16, 2019 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.