Magento 2 adds a filter to the collection

I created a grid in admin using XML interface components. I need to filter a collection through a URL parameter, and I don't know how to achieve this. I tried to enter RequestInterface into the collection, but the filter did not work.

di.xml

<virtualType name="SlideListingDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">xxx\xxx\Model\ResourceModel\Grid\Slide\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">SlideListingFilterPool</argument> <!-- Define new object for filters -->
        </arguments>
    </virtualType>

    <virtualType name="SlideListingFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="xxx\xxx\Model\ResourceModel\Grid\Slide\Collection" type="xxx\xxx\Ui\Component\DataProvider\SearchResult\Slide">
        <arguments>
            <argument name="mainTable" xsi:type="string">advox_sliders_slide</argument>
            <argument name="resourceModel" xsi:type="string">xxx\xxx\Model\ResourceModel\Slide</argument>
        </arguments>
    </virtualType>
+4
source share
1 answer

you need to write after update_url in ui components

`<item name="update_url" xsi:type="url" path="mui/index/render"/>`

after this line you should add below code

<item name="filter_url_params" xsi:type="array"> <item name="status" xsi:type="boolean">1</item> </item>

Now you need to pass the status value in the URL.

0
source

Source: https://habr.com/ru/post/1649389/


All Articles