How to add collection filter to gridContainer in Magento 2? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can i rewrite TierPrice Block in Magento2Argument problem when passed to Model in custom extensionMagento 2 : resource name is not definedMagento 2: What's the Difference Between the Two Grid Component Data Providers?Ui Template / Adminhtml issueAdminhtml Grid giving error Magento 2Magento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formunable to solve the error in magento2Magento2 REST API get all customers details

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

GDP with Intermediate Production

How to ternary Plot3D a function

Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?

A term for a woman complaining about things/begging in a cute/childish way

What is the chair depicted in Cesare Maccari's 1889 painting "Cicerone denuncia Catilina"?

Why is it faster to reheat something than it is to cook it?

Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?

What are the main differences between Stargate SG-1 cuts?

Select every other edge (they share a common vertex)

Trying to understand entropy as a novice in thermodynamics

retrieve food groups from food item list

Is CEO the "profession" with the most psychopaths?

Mounting TV on a weird wall that has some material between the drywall and stud

Random body shuffle every night—can we still function?

Is multiple magic items in one inherently imbalanced?

Tips to organize LaTeX presentations for a semester

Are the endpoints of the domain of a function counted as critical points?

How can a team of shapeshifters communicate?

What is the difference between CTSS and ITS?

Does silver oxide react with hydrogen sulfide?

NERDTreeMenu Remapping

How many time has Arya actually used Needle?



How to add collection filter to gridContainer in Magento 2?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How can i rewrite TierPrice Block in Magento2Argument problem when passed to Model in custom extensionMagento 2 : resource name is not definedMagento 2: What's the Difference Between the Two Grid Component Data Providers?Ui Template / Adminhtml issueAdminhtml Grid giving error Magento 2Magento 2.1 Create a filter in the product grid by new attributeMagento 2 Add new field to Magento_User admin formunable to solve the error in magento2Magento2 REST API get all customers details



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case.



I'm using gridContainer instead of usual way.



Here is my files:



layout.xml



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<uiComponent name="test_module_listing"/>
</referenceContainer>
</body>
</page>


ui_component.xml



<?xml version="1.0" encoding="UTF-8"?>
<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">test_modules_listing.integration_upload_listing_data_source</item>
<item name="deps" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">test_modules_columns</item>
</argument>
<dataSource name="test_modules_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">TestGridDataProvider</argument>
<argument name="name" xsi:type="string">test_modules_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">unique_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>
</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>
<container name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">ui/grid/toolbar</item>
</item>
</argument>
<bookmark name="bookmarks">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/bookmarks/bookmarks</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="storageConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="mui/bookmark/save"/>
<item name="deleteUrl" xsi:type="url" path="mui/bookmark/delete"/>
<item name="namespace" xsi:type="string">test_modules_listing</item>
</item>
</item>
</argument>
</bookmark>
<container name="columns_controls">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="columnsData" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns</item>
</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
</item>
</argument>
</container>
<filterSearch name="fulltext">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/search/search</item>
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="provider" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
<item name="chipsProvider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters_chips</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.search</item>
</item>
</item>
</argument>
</filterSearch>
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="dataScope" xsi:type="string">filters</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.filters</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
<item name="imports" xsi:type="array">
<item name="visible" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks:current.columns.$ $.index .visible</item>
</item>
</item>
</item>
</argument>
<filterRange name="unique_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">unique_id</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
</item>
</item>
</argument>
<filterInput name="from">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">from</item>
<item name="label" xsi:type="string" translate="true">from</item>
<item name="placeholder" xsi:type="string" translate="true">From</item>
</item>
</argument>
</filterInput>
<filterInput name="to">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">to</item>
<item name="label" xsi:type="string" translate="true">to</item>
<item name="placeholder" xsi:type="string" translate="true">To</item>
</item>
</argument>
</filterInput>
</filterRange>
......
</filters>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="customerexport/upload/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete items</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.paging</item>
</item>
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="options" xsi:type="array">
<item name="20" xsi:type="array">
<item name="value" xsi:type="number">20</item>
<item name="label" xsi:type="string" translate="true">20</item>
</item>
<item name="30" xsi:type="array">
<item name="value" xsi:type="number">30</item>
<item name="label" xsi:type="string" translate="true">30</item>
</item>
<item name="50" xsi:type="array">
<item name="value" xsi:type="number">50</item>
<item name="label" xsi:type="string" translate="true">50</item>
</item>
<item name="100" xsi:type="array">
<item name="value" xsi:type="number">100</item>
<item name="label" xsi:type="string" translate="true">100</item>
</item>
<item name="200" xsi:type="array">
<item name="value" xsi:type="number">200</item>
<item name="label" xsi:type="string" translate="true">200</item>
</item>
</item>
</item>
</argument>
</paging>
</container>
<columns name="test_modules_columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.actions</item>
<item name="target" xsi:type="string">applyAction</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">edit</item>
<item name="1" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
<item name="controlVisibility" xsi:type="boolean">true</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.$ $.index </item>
<item name="namespace" xsi:type="string">current.$ $.storageConfig.root</item>
</item>
</item>
</item>
</argument>
<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">unique_id</item>
</item>
</argument>
</selectionsColumn>

<column name="unique_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="source_type">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">TestModulesModelSomethingSourceSourceType</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="editor" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Source Type</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class="TestModulesUiComponentListingColumnTestActions">
<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">107</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
</actionsColumn>
</columns>
</listing>


di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="TestModulesApiDataTestInterface" type="TestModulesModelTest" />
<virtualType name="TestGridFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="TestGridDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">TestModulesModelResourceTestCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">TestGridFilterPool</argument>
</arguments>
</virtualType>
<virtualType name="TestModulesModelResourceModelTestGridCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">test_modules_test</argument>
<argument name="resourceModel" xsi:type="string">TestModulesModelResourceModelTest</argument>
</arguments>
</virtualType>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestGridCollection</item>
</argument>
</arguments>
</type>
</config>


Well, the final di.xml is from another module which I will call it module A, module A collection and grid collection are being used by module B, C,..etc



layout.xml (file in view/adminhtml/layout folder) and ui_component.xml (file in view/adminhtml/ui_component folder) are files from children modules (B, C, ... Z).



The concept here is keep module A does everything for its children, it suppose to has only one collection and only one data source.



The questions are:



  • Is is possible to filter a collection if keep using GridContainer (MagentoBackendBlockWidgetGridContainer) in Magento 2?

  • Why MagentoBackendBlockWidgetGridContainer doesn't have _prepareCollection() method?

  • How to override _prepareCollection() if my Block.php is extending from MagentoBackendBlockWidgetGridContainer

I tried to put a Grid.php under TestModulesBlockAdminhtmlTest but it just simply not working.



Grid.php



<?php
namespace TestModulesBlockAdminhtmlTest;

class Grid extends MagentoBackendBlockWidgetGrid

protected function _prepareCollection()

$this->setDefaultFilter(array('field_need_to_filter' => 'value'));
return parent::_prepareCollection();




UPDATED (05/05/16: 1462431094)



Here is my collection file



Collection.php



<?php
namespace TestModulesModelResourceModelTest;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection

/**
* @var string
*/
protected $_idFieldName = 'unique_id';

/**
* Define resource model
*
* @return void
*/
protected function _construct()

$this->_init('TestModulesModelTest', 'TestModulesModelResourceModelTest');




UPDATED (05/05/16: 1462438671)



There is no separate collection for grid (You can know that by reading my di.xml).



UPDATED (05/05/16: 1462440386)



In case you don't like to read. I would like to add different filter to different modules. Those modules are extending from module A, this can be done by create multiple different collection in my module A. But I don't like that, I feel comfortable with my current structure. Keep it be unique and other modules must extend and call it father.



All I need now is how to add a filter in Grid(s)



Does it make sense?










share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

    – Prashant Valanda
    May 5 '16 at 5:42











  • @PrashantValanda: Please check, I've just added collection file.

    – Toan Nguyen
    May 5 '16 at 6:53











  • Is this separate collection for grid? Have you created separate collection file for grid?

    – Prashant Valanda
    May 5 '16 at 7:35











  • @PrashantValanda There is no separate collection for grid. Take a look on my di.xml

    – Toan Nguyen
    May 5 '16 at 8:55

















2















I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case.



I'm using gridContainer instead of usual way.



Here is my files:



layout.xml



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<uiComponent name="test_module_listing"/>
</referenceContainer>
</body>
</page>


ui_component.xml



<?xml version="1.0" encoding="UTF-8"?>
<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">test_modules_listing.integration_upload_listing_data_source</item>
<item name="deps" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">test_modules_columns</item>
</argument>
<dataSource name="test_modules_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">TestGridDataProvider</argument>
<argument name="name" xsi:type="string">test_modules_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">unique_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>
</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>
<container name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">ui/grid/toolbar</item>
</item>
</argument>
<bookmark name="bookmarks">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/bookmarks/bookmarks</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="storageConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="mui/bookmark/save"/>
<item name="deleteUrl" xsi:type="url" path="mui/bookmark/delete"/>
<item name="namespace" xsi:type="string">test_modules_listing</item>
</item>
</item>
</argument>
</bookmark>
<container name="columns_controls">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="columnsData" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns</item>
</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
</item>
</argument>
</container>
<filterSearch name="fulltext">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/search/search</item>
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="provider" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
<item name="chipsProvider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters_chips</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.search</item>
</item>
</item>
</argument>
</filterSearch>
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="dataScope" xsi:type="string">filters</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.filters</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
<item name="imports" xsi:type="array">
<item name="visible" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks:current.columns.$ $.index .visible</item>
</item>
</item>
</item>
</argument>
<filterRange name="unique_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">unique_id</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
</item>
</item>
</argument>
<filterInput name="from">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">from</item>
<item name="label" xsi:type="string" translate="true">from</item>
<item name="placeholder" xsi:type="string" translate="true">From</item>
</item>
</argument>
</filterInput>
<filterInput name="to">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">to</item>
<item name="label" xsi:type="string" translate="true">to</item>
<item name="placeholder" xsi:type="string" translate="true">To</item>
</item>
</argument>
</filterInput>
</filterRange>
......
</filters>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="customerexport/upload/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete items</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.paging</item>
</item>
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="options" xsi:type="array">
<item name="20" xsi:type="array">
<item name="value" xsi:type="number">20</item>
<item name="label" xsi:type="string" translate="true">20</item>
</item>
<item name="30" xsi:type="array">
<item name="value" xsi:type="number">30</item>
<item name="label" xsi:type="string" translate="true">30</item>
</item>
<item name="50" xsi:type="array">
<item name="value" xsi:type="number">50</item>
<item name="label" xsi:type="string" translate="true">50</item>
</item>
<item name="100" xsi:type="array">
<item name="value" xsi:type="number">100</item>
<item name="label" xsi:type="string" translate="true">100</item>
</item>
<item name="200" xsi:type="array">
<item name="value" xsi:type="number">200</item>
<item name="label" xsi:type="string" translate="true">200</item>
</item>
</item>
</item>
</argument>
</paging>
</container>
<columns name="test_modules_columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.actions</item>
<item name="target" xsi:type="string">applyAction</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">edit</item>
<item name="1" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
<item name="controlVisibility" xsi:type="boolean">true</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.$ $.index </item>
<item name="namespace" xsi:type="string">current.$ $.storageConfig.root</item>
</item>
</item>
</item>
</argument>
<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">unique_id</item>
</item>
</argument>
</selectionsColumn>

<column name="unique_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="source_type">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">TestModulesModelSomethingSourceSourceType</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="editor" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Source Type</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class="TestModulesUiComponentListingColumnTestActions">
<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">107</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
</actionsColumn>
</columns>
</listing>


di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="TestModulesApiDataTestInterface" type="TestModulesModelTest" />
<virtualType name="TestGridFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="TestGridDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">TestModulesModelResourceTestCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">TestGridFilterPool</argument>
</arguments>
</virtualType>
<virtualType name="TestModulesModelResourceModelTestGridCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">test_modules_test</argument>
<argument name="resourceModel" xsi:type="string">TestModulesModelResourceModelTest</argument>
</arguments>
</virtualType>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestGridCollection</item>
</argument>
</arguments>
</type>
</config>


Well, the final di.xml is from another module which I will call it module A, module A collection and grid collection are being used by module B, C,..etc



layout.xml (file in view/adminhtml/layout folder) and ui_component.xml (file in view/adminhtml/ui_component folder) are files from children modules (B, C, ... Z).



The concept here is keep module A does everything for its children, it suppose to has only one collection and only one data source.



The questions are:



  • Is is possible to filter a collection if keep using GridContainer (MagentoBackendBlockWidgetGridContainer) in Magento 2?

  • Why MagentoBackendBlockWidgetGridContainer doesn't have _prepareCollection() method?

  • How to override _prepareCollection() if my Block.php is extending from MagentoBackendBlockWidgetGridContainer

I tried to put a Grid.php under TestModulesBlockAdminhtmlTest but it just simply not working.



Grid.php



<?php
namespace TestModulesBlockAdminhtmlTest;

class Grid extends MagentoBackendBlockWidgetGrid

protected function _prepareCollection()

$this->setDefaultFilter(array('field_need_to_filter' => 'value'));
return parent::_prepareCollection();




UPDATED (05/05/16: 1462431094)



Here is my collection file



Collection.php



<?php
namespace TestModulesModelResourceModelTest;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection

/**
* @var string
*/
protected $_idFieldName = 'unique_id';

/**
* Define resource model
*
* @return void
*/
protected function _construct()

$this->_init('TestModulesModelTest', 'TestModulesModelResourceModelTest');




UPDATED (05/05/16: 1462438671)



There is no separate collection for grid (You can know that by reading my di.xml).



UPDATED (05/05/16: 1462440386)



In case you don't like to read. I would like to add different filter to different modules. Those modules are extending from module A, this can be done by create multiple different collection in my module A. But I don't like that, I feel comfortable with my current structure. Keep it be unique and other modules must extend and call it father.



All I need now is how to add a filter in Grid(s)



Does it make sense?










share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

    – Prashant Valanda
    May 5 '16 at 5:42











  • @PrashantValanda: Please check, I've just added collection file.

    – Toan Nguyen
    May 5 '16 at 6:53











  • Is this separate collection for grid? Have you created separate collection file for grid?

    – Prashant Valanda
    May 5 '16 at 7:35











  • @PrashantValanda There is no separate collection for grid. Take a look on my di.xml

    – Toan Nguyen
    May 5 '16 at 8:55













2












2








2


1






I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case.



I'm using gridContainer instead of usual way.



Here is my files:



layout.xml



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<uiComponent name="test_module_listing"/>
</referenceContainer>
</body>
</page>


ui_component.xml



<?xml version="1.0" encoding="UTF-8"?>
<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">test_modules_listing.integration_upload_listing_data_source</item>
<item name="deps" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">test_modules_columns</item>
</argument>
<dataSource name="test_modules_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">TestGridDataProvider</argument>
<argument name="name" xsi:type="string">test_modules_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">unique_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>
</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>
<container name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">ui/grid/toolbar</item>
</item>
</argument>
<bookmark name="bookmarks">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/bookmarks/bookmarks</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="storageConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="mui/bookmark/save"/>
<item name="deleteUrl" xsi:type="url" path="mui/bookmark/delete"/>
<item name="namespace" xsi:type="string">test_modules_listing</item>
</item>
</item>
</argument>
</bookmark>
<container name="columns_controls">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="columnsData" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns</item>
</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
</item>
</argument>
</container>
<filterSearch name="fulltext">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/search/search</item>
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="provider" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
<item name="chipsProvider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters_chips</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.search</item>
</item>
</item>
</argument>
</filterSearch>
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="dataScope" xsi:type="string">filters</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.filters</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
<item name="imports" xsi:type="array">
<item name="visible" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks:current.columns.$ $.index .visible</item>
</item>
</item>
</item>
</argument>
<filterRange name="unique_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">unique_id</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
</item>
</item>
</argument>
<filterInput name="from">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">from</item>
<item name="label" xsi:type="string" translate="true">from</item>
<item name="placeholder" xsi:type="string" translate="true">From</item>
</item>
</argument>
</filterInput>
<filterInput name="to">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">to</item>
<item name="label" xsi:type="string" translate="true">to</item>
<item name="placeholder" xsi:type="string" translate="true">To</item>
</item>
</argument>
</filterInput>
</filterRange>
......
</filters>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="customerexport/upload/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete items</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.paging</item>
</item>
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="options" xsi:type="array">
<item name="20" xsi:type="array">
<item name="value" xsi:type="number">20</item>
<item name="label" xsi:type="string" translate="true">20</item>
</item>
<item name="30" xsi:type="array">
<item name="value" xsi:type="number">30</item>
<item name="label" xsi:type="string" translate="true">30</item>
</item>
<item name="50" xsi:type="array">
<item name="value" xsi:type="number">50</item>
<item name="label" xsi:type="string" translate="true">50</item>
</item>
<item name="100" xsi:type="array">
<item name="value" xsi:type="number">100</item>
<item name="label" xsi:type="string" translate="true">100</item>
</item>
<item name="200" xsi:type="array">
<item name="value" xsi:type="number">200</item>
<item name="label" xsi:type="string" translate="true">200</item>
</item>
</item>
</item>
</argument>
</paging>
</container>
<columns name="test_modules_columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.actions</item>
<item name="target" xsi:type="string">applyAction</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">edit</item>
<item name="1" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
<item name="controlVisibility" xsi:type="boolean">true</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.$ $.index </item>
<item name="namespace" xsi:type="string">current.$ $.storageConfig.root</item>
</item>
</item>
</item>
</argument>
<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">unique_id</item>
</item>
</argument>
</selectionsColumn>

<column name="unique_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="source_type">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">TestModulesModelSomethingSourceSourceType</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="editor" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Source Type</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class="TestModulesUiComponentListingColumnTestActions">
<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">107</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
</actionsColumn>
</columns>
</listing>


di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="TestModulesApiDataTestInterface" type="TestModulesModelTest" />
<virtualType name="TestGridFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="TestGridDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">TestModulesModelResourceTestCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">TestGridFilterPool</argument>
</arguments>
</virtualType>
<virtualType name="TestModulesModelResourceModelTestGridCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">test_modules_test</argument>
<argument name="resourceModel" xsi:type="string">TestModulesModelResourceModelTest</argument>
</arguments>
</virtualType>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestGridCollection</item>
</argument>
</arguments>
</type>
</config>


Well, the final di.xml is from another module which I will call it module A, module A collection and grid collection are being used by module B, C,..etc



layout.xml (file in view/adminhtml/layout folder) and ui_component.xml (file in view/adminhtml/ui_component folder) are files from children modules (B, C, ... Z).



The concept here is keep module A does everything for its children, it suppose to has only one collection and only one data source.



The questions are:



  • Is is possible to filter a collection if keep using GridContainer (MagentoBackendBlockWidgetGridContainer) in Magento 2?

  • Why MagentoBackendBlockWidgetGridContainer doesn't have _prepareCollection() method?

  • How to override _prepareCollection() if my Block.php is extending from MagentoBackendBlockWidgetGridContainer

I tried to put a Grid.php under TestModulesBlockAdminhtmlTest but it just simply not working.



Grid.php



<?php
namespace TestModulesBlockAdminhtmlTest;

class Grid extends MagentoBackendBlockWidgetGrid

protected function _prepareCollection()

$this->setDefaultFilter(array('field_need_to_filter' => 'value'));
return parent::_prepareCollection();




UPDATED (05/05/16: 1462431094)



Here is my collection file



Collection.php



<?php
namespace TestModulesModelResourceModelTest;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection

/**
* @var string
*/
protected $_idFieldName = 'unique_id';

/**
* Define resource model
*
* @return void
*/
protected function _construct()

$this->_init('TestModulesModelTest', 'TestModulesModelResourceModelTest');




UPDATED (05/05/16: 1462438671)



There is no separate collection for grid (You can know that by reading my di.xml).



UPDATED (05/05/16: 1462440386)



In case you don't like to read. I would like to add different filter to different modules. Those modules are extending from module A, this can be done by create multiple different collection in my module A. But I don't like that, I feel comfortable with my current structure. Keep it be unique and other modules must extend and call it father.



All I need now is how to add a filter in Grid(s)



Does it make sense?










share|improve this question
















I need to add a collection filter to my grid. I do few search on Internet but unfortunately it can't resolve my case.



I'm using gridContainer instead of usual way.



Here is my files:



layout.xml



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<uiComponent name="test_module_listing"/>
</referenceContainer>
</body>
</page>


ui_component.xml



<?xml version="1.0" encoding="UTF-8"?>
<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">test_modules_listing.integration_upload_listing_data_source</item>
<item name="deps" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">test_modules_columns</item>
</argument>
<dataSource name="test_modules_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">TestGridDataProvider</argument>
<argument name="name" xsi:type="string">test_modules_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">unique_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>
</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>
<container name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">ui/grid/toolbar</item>
</item>
</argument>
<bookmark name="bookmarks">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/bookmarks/bookmarks</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
<item name="storageConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="mui/bookmark/save"/>
<item name="deleteUrl" xsi:type="url" path="mui/bookmark/delete"/>
<item name="namespace" xsi:type="string">test_modules_listing</item>
</item>
</item>
</argument>
</bookmark>
<container name="columns_controls">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="columnsData" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns</item>
</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
</item>
</argument>
</container>
<filterSearch name="fulltext">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/search/search</item>
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="provider" xsi:type="string">test_modules_listing.integration_upload_listing_data_source</item>
<item name="chipsProvider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters_chips</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.search</item>
</item>
</item>
</argument>
</filterSearch>
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="displayArea" xsi:type="string">dataGridFilters</item>
<item name="dataScope" xsi:type="string">filters</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.filters</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
<item name="imports" xsi:type="array">
<item name="visible" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks:current.columns.$ $.index .visible</item>
</item>
</item>
</item>
</argument>
<filterRange name="unique_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">unique_id</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="childDefaults" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.listing_filters</item>
</item>
</item>
</argument>
<filterInput name="from">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">from</item>
<item name="label" xsi:type="string" translate="true">from</item>
<item name="placeholder" xsi:type="string" translate="true">From</item>
</item>
</argument>
</filterInput>
<filterInput name="to">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataScope" xsi:type="string">to</item>
<item name="label" xsi:type="string" translate="true">to</item>
<item name="placeholder" xsi:type="string" translate="true">To</item>
</item>
</argument>
</filterInput>
</filterRange>
......
</filters>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="customerexport/upload/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete items</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.paging</item>
</item>
<item name="selectProvider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="options" xsi:type="array">
<item name="20" xsi:type="array">
<item name="value" xsi:type="number">20</item>
<item name="label" xsi:type="string" translate="true">20</item>
</item>
<item name="30" xsi:type="array">
<item name="value" xsi:type="number">30</item>
<item name="label" xsi:type="string" translate="true">30</item>
</item>
<item name="50" xsi:type="array">
<item name="value" xsi:type="number">50</item>
<item name="label" xsi:type="string" translate="true">50</item>
</item>
<item name="100" xsi:type="array">
<item name="value" xsi:type="number">100</item>
<item name="label" xsi:type="string" translate="true">100</item>
</item>
<item name="200" xsi:type="array">
<item name="value" xsi:type="number">200</item>
<item name="label" xsi:type="string" translate="true">200</item>
</item>
</item>
</item>
</argument>
</paging>
</container>
<columns name="test_modules_columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.test_modules_columns.actions</item>
<item name="target" xsi:type="string">applyAction</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">edit</item>
<item name="1" xsi:type="string">$ $.$data.rowIndex </item>
</item>
</item>
<item name="controlVisibility" xsi:type="boolean">true</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">test_modules_listing.test_modules_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.$ $.index </item>
<item name="namespace" xsi:type="string">current.$ $.storageConfig.root</item>
</item>
</item>
</item>
</argument>
<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">unique_id</item>
</item>
</argument>
</selectionsColumn>

<column name="unique_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="source_type">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">TestModulesModelSomethingSourceSourceType</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="editor" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Source Type</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class="TestModulesUiComponentListingColumnTestActions">
<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">107</item>
<item name="indexField" xsi:type="string">unique_id</item>
</item>
</argument>
</actionsColumn>
</columns>
</listing>


di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="TestModulesApiDataTestInterface" type="TestModulesModelTest" />
<virtualType name="TestGridFilterPool" type="MagentoFrameworkViewElementUiComponentDataProviderFilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderRegularFilter</item>
<item name="fulltext" xsi:type="object">MagentoFrameworkViewElementUiComponentDataProviderFulltextFilter</item>
</argument>
</arguments>
</virtualType>
<virtualType name="TestGridDataProvider" type="MagentoFrameworkViewElementUiComponentDataProviderDataProvider">
<arguments>
<argument name="collection" xsi:type="object" shared="false">TestModulesModelResourceTestCollection</argument>
<argument name="filterPool" xsi:type="object" shared="false">TestGridFilterPool</argument>
</arguments>
</virtualType>
<virtualType name="TestModulesModelResourceModelTestGridCollection" type="MagentoFrameworkViewElementUiComponentDataProviderSearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">test_modules_test</argument>
<argument name="resourceModel" xsi:type="string">TestModulesModelResourceModelTest</argument>
</arguments>
</virtualType>
<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestGridCollection</item>
</argument>
</arguments>
</type>
</config>


Well, the final di.xml is from another module which I will call it module A, module A collection and grid collection are being used by module B, C,..etc



layout.xml (file in view/adminhtml/layout folder) and ui_component.xml (file in view/adminhtml/ui_component folder) are files from children modules (B, C, ... Z).



The concept here is keep module A does everything for its children, it suppose to has only one collection and only one data source.



The questions are:



  • Is is possible to filter a collection if keep using GridContainer (MagentoBackendBlockWidgetGridContainer) in Magento 2?

  • Why MagentoBackendBlockWidgetGridContainer doesn't have _prepareCollection() method?

  • How to override _prepareCollection() if my Block.php is extending from MagentoBackendBlockWidgetGridContainer

I tried to put a Grid.php under TestModulesBlockAdminhtmlTest but it just simply not working.



Grid.php



<?php
namespace TestModulesBlockAdminhtmlTest;

class Grid extends MagentoBackendBlockWidgetGrid

protected function _prepareCollection()

$this->setDefaultFilter(array('field_need_to_filter' => 'value'));
return parent::_prepareCollection();




UPDATED (05/05/16: 1462431094)



Here is my collection file



Collection.php



<?php
namespace TestModulesModelResourceModelTest;

use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection

/**
* @var string
*/
protected $_idFieldName = 'unique_id';

/**
* Define resource model
*
* @return void
*/
protected function _construct()

$this->_init('TestModulesModelTest', 'TestModulesModelResourceModelTest');




UPDATED (05/05/16: 1462438671)



There is no separate collection for grid (You can know that by reading my di.xml).



UPDATED (05/05/16: 1462440386)



In case you don't like to read. I would like to add different filter to different modules. Those modules are extending from module A, this can be done by create multiple different collection in my module A. But I don't like that, I feel comfortable with my current structure. Keep it be unique and other modules must extend and call it father.



All I need now is how to add a filter in Grid(s)



Does it make sense?







magento2 collection grid filter grid-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 16 '16 at 8:01







Toan Nguyen

















asked May 5 '16 at 3:13









Toan NguyenToan Nguyen

2,0121138




2,0121138





bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

    – Prashant Valanda
    May 5 '16 at 5:42











  • @PrashantValanda: Please check, I've just added collection file.

    – Toan Nguyen
    May 5 '16 at 6:53











  • Is this separate collection for grid? Have you created separate collection file for grid?

    – Prashant Valanda
    May 5 '16 at 7:35











  • @PrashantValanda There is no separate collection for grid. Take a look on my di.xml

    – Toan Nguyen
    May 5 '16 at 8:55

















  • Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

    – Prashant Valanda
    May 5 '16 at 5:42











  • @PrashantValanda: Please check, I've just added collection file.

    – Toan Nguyen
    May 5 '16 at 6:53











  • Is this separate collection for grid? Have you created separate collection file for grid?

    – Prashant Valanda
    May 5 '16 at 7:35











  • @PrashantValanda There is no separate collection for grid. Take a look on my di.xml

    – Toan Nguyen
    May 5 '16 at 8:55
















Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

– Prashant Valanda
May 5 '16 at 5:42





Do you have TestModulesModelResourceModelUploadTestCollection collection file? If yes update your question with code of collection file.

– Prashant Valanda
May 5 '16 at 5:42













@PrashantValanda: Please check, I've just added collection file.

– Toan Nguyen
May 5 '16 at 6:53





@PrashantValanda: Please check, I've just added collection file.

– Toan Nguyen
May 5 '16 at 6:53













Is this separate collection for grid? Have you created separate collection file for grid?

– Prashant Valanda
May 5 '16 at 7:35





Is this separate collection for grid? Have you created separate collection file for grid?

– Prashant Valanda
May 5 '16 at 7:35













@PrashantValanda There is no separate collection for grid. Take a look on my di.xml

– Toan Nguyen
May 5 '16 at 8:55





@PrashantValanda There is no separate collection for grid. Take a look on my di.xml

– Toan Nguyen
May 5 '16 at 8:55










1 Answer
1






active

oldest

votes


















0














Create a collection file for grid code as below:



<?php

namespace TestModulesModelResourceModelTestGrid;

use MagentoFrameworkApiSearchSearchResultInterface;
use MagentoFrameworkSearchAggregationInterface;
use TestModulesModelResourceModelUploadTestCollection as TestCollection;


class Collection extends TestCollection implements SearchResultInterface


protected $aggregations;


public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument',
$connection,
MagentoFrameworkModelResourceModelDbAbstractDb $resource
)
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);



public function getAggregations()

return $this->aggregations;



public function setAggregations($aggregations)

$this->aggregations = $aggregations;




public function getAllIds($limit = null, $offset = null)

return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);



public function getSearchCriteria()

return null;



public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)

return $this;



public function getTotalCount()

return $this->getSize();



public function setTotalCount($totalCount)

return $this;



public function setItems(array $items = null)

return $this;




Replace below code in di.xml



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestCollection</item>
</argument>
</arguments>
</type>


Replce to:



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelTestGridCollection</item>
</argument>
</arguments>
</type>





share|improve this answer























  • It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

    – Toan Nguyen
    May 5 '16 at 9:25












  • By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

    – Toan Nguyen
    Jun 16 '16 at 8:00











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f114003%2fhow-to-add-collection-filter-to-gridcontainer-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Create a collection file for grid code as below:



<?php

namespace TestModulesModelResourceModelTestGrid;

use MagentoFrameworkApiSearchSearchResultInterface;
use MagentoFrameworkSearchAggregationInterface;
use TestModulesModelResourceModelUploadTestCollection as TestCollection;


class Collection extends TestCollection implements SearchResultInterface


protected $aggregations;


public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument',
$connection,
MagentoFrameworkModelResourceModelDbAbstractDb $resource
)
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);



public function getAggregations()

return $this->aggregations;



public function setAggregations($aggregations)

$this->aggregations = $aggregations;




public function getAllIds($limit = null, $offset = null)

return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);



public function getSearchCriteria()

return null;



public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)

return $this;



public function getTotalCount()

return $this->getSize();



public function setTotalCount($totalCount)

return $this;



public function setItems(array $items = null)

return $this;




Replace below code in di.xml



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestCollection</item>
</argument>
</arguments>
</type>


Replce to:



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelTestGridCollection</item>
</argument>
</arguments>
</type>





share|improve this answer























  • It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

    – Toan Nguyen
    May 5 '16 at 9:25












  • By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

    – Toan Nguyen
    Jun 16 '16 at 8:00















0














Create a collection file for grid code as below:



<?php

namespace TestModulesModelResourceModelTestGrid;

use MagentoFrameworkApiSearchSearchResultInterface;
use MagentoFrameworkSearchAggregationInterface;
use TestModulesModelResourceModelUploadTestCollection as TestCollection;


class Collection extends TestCollection implements SearchResultInterface


protected $aggregations;


public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument',
$connection,
MagentoFrameworkModelResourceModelDbAbstractDb $resource
)
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);



public function getAggregations()

return $this->aggregations;



public function setAggregations($aggregations)

$this->aggregations = $aggregations;




public function getAllIds($limit = null, $offset = null)

return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);



public function getSearchCriteria()

return null;



public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)

return $this;



public function getTotalCount()

return $this->getSize();



public function setTotalCount($totalCount)

return $this;



public function setItems(array $items = null)

return $this;




Replace below code in di.xml



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestCollection</item>
</argument>
</arguments>
</type>


Replce to:



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelTestGridCollection</item>
</argument>
</arguments>
</type>





share|improve this answer























  • It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

    – Toan Nguyen
    May 5 '16 at 9:25












  • By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

    – Toan Nguyen
    Jun 16 '16 at 8:00













0












0








0







Create a collection file for grid code as below:



<?php

namespace TestModulesModelResourceModelTestGrid;

use MagentoFrameworkApiSearchSearchResultInterface;
use MagentoFrameworkSearchAggregationInterface;
use TestModulesModelResourceModelUploadTestCollection as TestCollection;


class Collection extends TestCollection implements SearchResultInterface


protected $aggregations;


public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument',
$connection,
MagentoFrameworkModelResourceModelDbAbstractDb $resource
)
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);



public function getAggregations()

return $this->aggregations;



public function setAggregations($aggregations)

$this->aggregations = $aggregations;




public function getAllIds($limit = null, $offset = null)

return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);



public function getSearchCriteria()

return null;



public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)

return $this;



public function getTotalCount()

return $this->getSize();



public function setTotalCount($totalCount)

return $this;



public function setItems(array $items = null)

return $this;




Replace below code in di.xml



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestCollection</item>
</argument>
</arguments>
</type>


Replce to:



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelTestGridCollection</item>
</argument>
</arguments>
</type>





share|improve this answer













Create a collection file for grid code as below:



<?php

namespace TestModulesModelResourceModelTestGrid;

use MagentoFrameworkApiSearchSearchResultInterface;
use MagentoFrameworkSearchAggregationInterface;
use TestModulesModelResourceModelUploadTestCollection as TestCollection;


class Collection extends TestCollection implements SearchResultInterface


protected $aggregations;


public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument',
$connection,
MagentoFrameworkModelResourceModelDbAbstractDb $resource
)
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);



public function getAggregations()

return $this->aggregations;



public function setAggregations($aggregations)

$this->aggregations = $aggregations;




public function getAllIds($limit = null, $offset = null)

return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);



public function getSearchCriteria()

return null;



public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)

return $this;



public function getTotalCount()

return $this->getSize();



public function setTotalCount($totalCount)

return $this;



public function setItems(array $items = null)

return $this;




Replace below code in di.xml



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelUploadTestCollection</item>
</argument>
</arguments>
</type>


Replce to:



<type name="MagentoFrameworkViewElementUiComponentDataProviderCollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="test_modules_listing_data_source" xsi:type="string">TestModulesModelResourceModelTestGridCollection</item>
</argument>
</arguments>
</type>






share|improve this answer












share|improve this answer



share|improve this answer










answered May 5 '16 at 9:02









Prashant ValandaPrashant Valanda

10k12356




10k12356












  • It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

    – Toan Nguyen
    May 5 '16 at 9:25












  • By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

    – Toan Nguyen
    Jun 16 '16 at 8:00

















  • It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

    – Toan Nguyen
    May 5 '16 at 9:25












  • By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

    – Toan Nguyen
    Jun 16 '16 at 8:00
















It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

– Toan Nguyen
May 5 '16 at 9:25






It doesn't help at all. It works exactly like my current collection. I used Dependency Injection, thanks Magento 2 for this new and powerful feature. What I need here is how to add a different filter for different children modules. Thanks anyway.

– Toan Nguyen
May 5 '16 at 9:25














By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

– Toan Nguyen
Jun 16 '16 at 8:00





By the way: There is no TestModulesModelResourceModelUploadTestCollection in my di.xml, it already defined by my virtualType

– Toan Nguyen
Jun 16 '16 at 8:00

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f114003%2fhow-to-add-collection-filter-to-gridcontainer-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko