cancel
Showing results for 
Search instead for 
Did you mean: 

magento 2 Admin Change grid data based on the selected options via ajax

SOLVED

magento 2 Admin Change grid data based on the selected options via ajax

I have an admin form inside which I have added a dropdown and one grid with UI component,

I want to change the grid data or need to apply filers to grid collection based on the selected value inside the dropdown

Ex. if I select option 1 then the grid will show data depending on that option and if I select option 2 then data is based on that value

how can I do this, Your help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions

Re: magento 2 Admin Change grid data based on the selected options via ajax

resolved this problem 
Please have a look at the below article for a solution 

 

https://smitakagwade.medium.com/magento-2-admin-form-ui-component-change-grid-data-based-on-the-sele...

 

Thank You.

View solution in original post

3 REPLIES 3

Re: magento 2 Admin Change grid data based on the selected options via ajax

Hi @smita_kagwade 

 

When you define your fields datatype and filter as select. Magento will automatically display your column filter as dropdown.

Below example code may help you :

<column name="type">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Namespace\Modulename\Model\Config\Source\Departments</item>
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">select</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="sortOrder" xsi:type="number">2</item>
                <item name="label" translate="true" xsi:type="string">Departments</item>
            </item>
        </argument>
    </column>

It may help you!
Thank you.

Problem solved? Click Accept as Solution!

Re: magento 2 Admin Change grid data based on the selected options via ajax

Hello @Bhanu Periwal ,

I don't want to show it at filters,

Want to refresh the grid based on the selected values in dropdown , The drop down is a separate field in admin form, and in the same form I have added a separate grid.

Re: magento 2 Admin Change grid data based on the selected options via ajax

resolved this problem 
Please have a look at the below article for a solution 

 

https://smitakagwade.medium.com/magento-2-admin-form-ui-component-change-grid-data-based-on-the-sele...

 

Thank You.