How to Filter Ui Component Grid Collection Magento 2 : Here we will see how to filter a collection in ui component grid. most of the time we have to display filtered collection in ui component grid. so for that we have to make some changes in our ui component grid file.
so i will elaborate it through the code.
1 => this code is a part of ui component grid xml file.
<dataSource name="test_comments_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">test_comments_listing_data_source</argument> <argument name="primaryFieldName" xsi:type="string">id</argument> <argument name="requestFieldName" xsi:type="string">id</argument> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="update_url" xsi:type="url" path="mui/index/render"/> <item name="filter_url_params" xsi:type="array"> <item name="status" xsi:type="string">*</item> </item> </item> </argument> </argument> <argument name="data" xsi:type="array"> <item name="js_config" xsi:type="array"> <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item> </item> </argument> </dataSource>
above code is a part of ui component xml file. where you have to make changes.
still it contains lots of line code. so now i am going to pick a chunk of code where exactly you have make changes.
<argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="update_url" xsi:type="url" path="mui/index/render"/> <item name="filter_url_params" xsi:type="array"> <item name="status" xsi:type="string">*</item> </item> </item> </argument>
inside an argument tag, you can see a item tag which attribute name is filter_url_params . this tag is responsible for filter your collection in ui grid component and for make it work you have to set the parameter name on inside name attribute of item tag through which you want to filter. in the above code i have made a filter by status on the collection and you have to pass the value of status through the url.
Hope it will help you.
5 comments
Thanks for the Appreciation.
With Regards,
Team Webkul
How to filter with multiple values ? Like 1,2 not all the values