8

I have created an attribute type: select but i can't display it in the grid customer. the code of my customer_listing.xml

<column name="customer_status">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">select</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="label" xsi:type="string" translate="true">Customer Status</item>
                <item name="sortOrder" xsi:type="number">190</item>
            </item>
        </argument>
    </column>

the code of the UpgradeData.php

$attributeCode7 = "customer_status";
    $customerSetup->addAttribute(Customer::ENTITY, $attributeCode7, [
        'type'              => 'varchar',
        'label'             => 'Customer Status',
        'input'             => 'select',
        'source'            => 'Stack\Customer\Model\Attribute\Source\CustomerStatus',
        'required'          => true,
        'visible'           => true,
        'user_defined'      => true,
        'sort_order'        => 1000,
        'position'          => 1000,
        'system'            => false,
        'is_used_in_grid'       => true,
        'is_visible_in_grid'    => true,

    ]);

    $attribute7 = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $attributeCode7)
        ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' =>  ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']
        ]);
    $attribute7->save();

also i created indexer.xml under etc of my module here is the code:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
<indexer id="customer_grid">
    <fieldset name="customer">
        <field name="customer_status" xsi:type="filterable" dataType="int"/>
    </fieldset>
</indexer>

please help me and thanks in advance

1 Answer 1

16

You don't need customer_listing.xml or indexer.xml to show customer attribute in gird. these line will do it for you

    'is_used_in_grid'       => true,
    'is_visible_in_grid'    => true,

Just run the following command. This will show your column in grid.

 php bin/magento indexer:reindex

Make sure Customer Grid index rebuilt Customer Grid index has been rebuilt successfully

New column of customer_status will be created customer_grid_flat table

16
  • thanks for your replay but i really put those two in the upgrade but nothing displayed Commented Nov 22, 2018 at 10:51
  • @DevelopperMagento did you run the command? make sure your you have entry in table eav_attribute and respectively customer_eav_attribute Commented Nov 22, 2018 at 10:55
  • yes i have the entry in customer_entity_varchar and the attribute is displayed in eav_attribute and when i click on add new user in BO Commented Nov 22, 2018 at 10:59
  • 3
    @DevelopperMagento, Did you select to show your custom attribute collumn ??!! From all collumn list at customer Grid.
    – anonymous
    Commented Nov 22, 2018 at 11:06
  • 1
    @Vivek forgot about that thanks for reminding me. Commented Nov 22, 2018 at 11:07

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.