0

I have created custom field in admin user creation form.Based on the value in this field,My custom module grid collection will be loaded.How to acheive this?

0

add this into your layout file

<uiComponent name="admin_user_listing"/>

app/code/VendoreName/ModuleName/etc/di.xml

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="admin_user_listing_data_source" xsi:type="string">Magento\User\Model\ResourceModel\User\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="Mageplaza\HelloWorld\Model\ResourceModel\Post\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">admin_user</argument>
            <argument name="resourceModel" xsi:type="string">Magento\User\Model\ResourceModel\User\Collection</argument>
        </arguments>
    </virtualType>
</config>

app/code/VendoreName/ModuleName/view/adminhtml/ui_component/admin_user_listing.xml

admin_user_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">admin_user_listing.admin_user_listing_data_source</item>
            <item name="deps" xsi:type="string">admin_user_listing.admin_user_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">spinner_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Add New Post</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">*/*/new</item>
            </item>
        </item>
    </argument>
    <dataSource name="nameOfDataSource">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
            <argument name="name" xsi:type="string">admin_user_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">user_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="indexField" xsi:type="string">user_id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="spinner_columns">
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">55</item>
                    <item name="indexField" xsi:type="string">user_id</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="user_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>
            </argument>
        </column>
        <column name="firstname">
            <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="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">First Name</item>
                </item>
            </argument>
        </column>
        <column name="created" class="Magento\Ui\Component\Listing\Columns\Date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                    <item name="dataType" xsi:type="string">date</item>
                    <item name="label" xsi:type="string" translate="true">Created</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

for more click here

Note: it's basically created on your previous question click here

|improve this answer|||||
  • I have already created one custom grid.It has column which I was created customly in admin creation form.based on that Customly created field in admin creation form my custom grid Collection will be filter. for example my custom admin form field value is 1,then in my custom grid only the rows which has custom admin form field value is 1 will be shown.Other than that all other rows are hidden – Jothi Subramanian Feb 22 at 12:16
0

This method is worked for me .I have changed by model file refering this https://webkul.com/blog/join-two-table-and-create-grid-in-admin-section-using-ui-component-in-magento2/ and then I have changed the _initSelect() instead of joinleft I used $this->getSelect()->where("main_table.user_id = ".$Id);

|improve this answer|||||

Your Answer

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

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