How to use default filters using UI component in admin grid Magento 2
Asked Answered
C

2

8

I want to apply default filters on records while using magento 2 admin grid using UI Component.

I know there is a way while using block to render admin grid but i want the way using UI component.

Cumulonimbus answered 31/10, 2016 at 21:6 Comment(1)
Did you find a solution to this?Bradstreet
H
1

Vanilla out of the box can achieve default filter

Inject the below configs to your listing component, e.g., your_ui_component.xml

<listing ...>
    <listingToolbar ...>
        <filters ...>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="applied" xsi:type="array">
                        <item name="is_approved" xsi:type="string">1</item>
                    </item>
                </item>
            </argument>
        </filters>
    </listingToolbar>
</listing>

Source/credits: https://magento.stackexchange.com/a/178663/39320

Hurtless answered 13/6, 2022 at 23:30 Comment(0)
S
-1

You can add this in your ui_component/custom_listing.xml which should create filter button in grid:

<listingToolbar name="listing_top">
    <filters name="listing_filters"/>
</listingToolbar>

And columns which should have been filtered needed to have "filter" field in column config, for ex.:

<column name="entity_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="sorting" xsi:type="string">asc</item>
                <item name="label" xsi:type="string" translate="true">Entity ID</item>
            </item>
        </argument>
    </column>
Synonym answered 8/2, 2022 at 6:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.