4

I want to add a where clause in customer grid collection. e.g.

$currentCollection->getSelect()->where('custom condition');

I tried to google it but got no success. I have also tried to implement customization methods used for product and order grid but it seems that di.xml and ui component xml files are different.

e.g when I try to add code

<argument name="addFieldStrategies" xsi:type="array">
        <item name="title" xsi:type="object">Namespace\Module\Ui\DataProvider\Test\AddTitleFieldToCollection</item>
</argument>

in file /app/code/Namespace/Module/view/adminhtml/ui_component/customer_listing.xml

I get

Element 'arguments': This element is not expected. Expected is ( argument ).

I have also tried modifying collection through observer but it seems event customer_grid_collection_load_before does not exist.

I don't want to modify core code and I have no clue from where to start. Please comment if any other information needed.

2
  • do you want this condition for every loaded customer, or you want to filter loaded collection after displaying a grid (for not every customer)? Commented Jun 24, 2016 at 14:34
  • I want to add filter to collection before grid is loaded. e.g. customer collection is loaded in variable $customerCollection then I want to add a where condition like $customerCollection->where('Custom condition goes here'); Commented Jun 25, 2016 at 5:07

1 Answer 1

2

EDIT I was wrong - in Magento 2 grid is built other way, look at this: http://webkul.com/blog/create-grid-edit-add-grid-row-and-installer-in-magento2/

And here you can find way to add custom filter for grid collection To add default filter to grid in Magento2?

1
  • This is the issue in which I am stuck. I am unable to find which block file is used or contains prepareCollection function. The module-customer uses /etc/di.xml and /view/ui_component/customer_listing.xml for displaying customer grid in admin section. Commented Jun 25, 2016 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.