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:
Please note above indexer attribute
view_id. it is customer_dummy (Which is default to native customer module). if I use the sameview_idname in my custom module I get error Customer grid index is locked by another reindex process. SkippingIf I use a different
view_idname and executephp bin/magento indexer:reindex customer_gridthen it shows view_id (in my case it justdummy) view does not exist.
2 Answers 2
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.
-
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?Magento Learner– Magento Learner2018年03月09日 10:48:40 +00:00Commented Mar 9, 2018 at 10:48
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.
Explore related questions
See similar questions with these tags.