3

I want to add a custom attribute to the admin customer grid. For that, I have added two attributes using ui_component.

The columns show up in the grid but without data from customer_grid_flat (because Magento 2 uses a flat grid table for retrieving data to the grid).

I found the following answer on StackExchange:

add a custom column in customer grid

According to that, I added an indexer.xml file to my custom module:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
 <indexer id="customer_grid" view_id="customer_dummy" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
 <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection" provider="Magento\Customer\Model\Indexer\AttributeProvider">
 <field name="webshop" xsi:type="filterable" dataType="int"/>
 <field name="aktiv" xsi:type="filterable" dataType="int"/>
 </fieldset>
 </indexer>
</config>

and executed php bin/magento indexer:reindex customer_grid.

Now, I face two different errors in two different conditions:

  1. Please note above indexer attribute view_id. it is customer_dummy (Which is default to native customer module). if I use the same view_id name in my custom module I get error Customer grid index is locked by another reindex process. Skipping

  2. If I use a different view_id name and execute php bin/magento indexer:reindex customer_grid then it shows view_id (in my case it just dummy) view does not exist.

asked Nov 10, 2016 at 13:23

2 Answers 2

6

Leaving out view_id seems to work:

<indexer id="customer_grid">

This way, the XML will be merged into the existing indexer instead of defining a new indexer.

answered Dec 13, 2016 at 14:21
1
  • I had the same issue, and your solution helped me to fix the problem. But in my case, I also have this view_id="dummy" in indexer.xml. but this view_id has always been there since I installed my custom extension, and the error wasn't there in the beginning. So I wonder why this view_id suddenly became a problem? Commented Mar 9, 2018 at 10:48
0

According to that, you can added an indexer.xml file to your custom module:

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="customer_grid" class="Magento\Framework\Indexer\Action\Entity" primary="customer">
 <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection" provider="Magento\Customer\Model\Indexer\AttributeProvider">
 <field name="account_number" xsi:type="filterable" dataType="varchar"/> 
 </fieldset>
</indexer>

Must be check your attribute datatype varchar or text etc..

Need to 'is_used_in_grid' => true and in di.xml add

 <preference for="Magento\Customer\Model\Indexer\Source" type="Magento\Customer\Model\ResourceModel\Customer\Collection" />

OR

<virtualType name="Magento\Customer\Model\Indexer\Source" type="Magento\Customer\Model\ResourceModel\Customer\Collection" />

And It's working.

answered Aug 9, 2018 at 10:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.