0

I am creating functionality where admin can set product's price specifically for a customer,

I created custom tab in the product edit page, where if someone click on add specific customer modal window shows up where all the customers are listed if someone select customer it will open the new page, store the data into database, and other grid which is on my custom tab shows the list of customer and specific price.

I created modal window, and its shows the list of all customers, but its not the grid which I set, it is like default grid which shows all the column as I don't know much about ui_component, I am trying to set my grid which only has 4 columns.

In my DataProvider:

protected function getModalConfig()
{
    return [
        'arguments' => [
            'data' => [
                'config' => [
                    'componentType' => Modal::NAME,
                    'dataScope' => '',
                    'provider' => static::FORM_NAME . '.product_form_data_source',
                    'ns' => static::FORM_NAME,
                    'options' => [
                        'title' => __('Modal Title'),
                        'buttons' => [
                            [
                                'text' => __('Save'),
                                'class' => 'action-primary', // additional class
                                'actions' => [
                                    [
                                        'targetName' => 'index = product_form', // Element selector
                                        'actionName' => 'save', // Save parent form (product)
                                    ],
                                    'closeModal', // method name
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'children' => [
            static::CUSTOM_MODAL_CONTENT => [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'autoRender' => false,
                            'componentType' => 'container',
                            'dataScope' => 'data.product', // save data in the product data
                            'externalProvider' => 'data.product_data_source',
                            'ns' => static::FORM_NAME,
                            'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
                            'realTimeLink' => true,
                            'behaviourType' => 'edit',
                            'externalFilterMode' => true,
                            'currentProductId' => $this->locator->getProduct()->getId(),
                        ],
                    ],
                ],
                'children' => [
                    static::SAMPLE_FIELD_NAME => [
                        'arguments' => [
                            'data' => [
                                'config' => [
                                    'autoRender' => true,
                                    'componentType' => 'insertListing',
                                    'dataScope' => 'customer_grid_listing',
                                    'externalProvider' => 'custom_listing.customer_grid_listing_data_source',
                                    'selectionsProvider' => 'custom_listing.custom_listing.product_columns.ids',
                                    'ns' => 'customer_grid_listing',
                                    'render_url' => $this->urlBuilder->getUrl('mui/index/render'),
                                    'realTimeLink' => false,
                                    'behaviourType' => 'simple',
                                    'externalFilterMode' => true,
                                    'imports' => [
                                        'productId' => '${ $.provider }:data.product.current_product_id'
                                    ],
                                    'exports' => [
                                        'productId' => '${ $.externalProvider }:params.current_product_id'
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ];
}

custom.grid.listing is grid which I want to show for all customer currently in my website.

custom.grid.listing.xml

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
        <item name="provider" xsi:type="string">customer_grid_listing.customer_grid_listing_data_source</item>
        <item name="deps" xsi:type="string">customer_grid_listing.customer_grid_listing_data_source</item>
    </item>
    <item name="spinner" xsi:type="string">customer_columns</item>
</argument>
<dataSource name="customer_grid_listing_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Magento\Customer\Ui\Component\DataProvider</argument>
        <argument name="name" xsi:type="string">customer_grid_listing_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                <item name="update_url" xsi:type="url" path="mui/index/render"/>
                <item name="storageConfig" xsi:type="array">
                    <item name="cacheRequests" xsi:type="boolean">false</item>
                </item>
            </item>
        </argument>
    </argument>
</dataSource>
<columns name="customer_columns" class="Magento\Customer\Ui\Component\Listing\Columns">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="childDefaults" xsi:type="array">
                <item name="fieldAction" xsi:type="array">
                    <item name="provider" xsi:type="string">customer_grid_listing.customer_grid_listing.customer_columns_editor</item>
                    <item name="target" xsi:type="string">selectCustomer</item>
                    <item name="params" xsi:type="array">
                        <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                    </item>
                </item>
            </item>
        </item>
    </argument>
    <selectionsColumn name="ids">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="indexField" xsi:type="string">entity_id</item>
                <item name="sortOrder" xsi:type="number">0</item>
                <item name="preserveSelectionsOnFilter" xsi:type="boolean">true</item>
            </item>
        </argument>
    </selectionsColumn>
    <column name="entity_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">textRange</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="label" xsi:type="string" translate="true">ID</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
    </column>
    <column name="name">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Name</item>
                <item name="sortOrder" xsi:type="number">30</item>
            </item>
        </argument>
    </column>
    <column name="email">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="editor" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Email</item>
                <item name="sortOrder" xsi:type="number">40</item>
            </item>
        </argument>
    </column>
</columns>
</listing>

as you can I created only 3 columns in the grid, but still its showing all the columns. you can see the screenshot at the end.

di.xml

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="customertab" xsi:type="array">
                <item name="class" xsi:type="string">SimpleMagento\ProductTabs\Ui\Dataprovider\Product\Form\Modifier\Modifier</item>
                <item name="sortOrder" xsi:type="number">110</item>
            </item>
        </argument>
    </arguments>
</virtualType>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="customer_grid_listing_data_source" xsi:type="string">Magento\Customer\Model\ResourceModel\Grid\Collection</item>
        </argument>
    </arguments>
</type>
</config>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.