Magento 2 - How to add a custom column in customer grid like (is approved)Add custom column and filter to customer grid from joined table in magento 2Magento 2 - How to add a custom column in customer gridMagento 2 : Change Admin grid column widthMagento 2 Filter not working while Custom column added on Sales Grid Using Ui ComponentMagento 2.1 : how to add profit column to admin order gridMagento 2 bar disappeared in Sales Order Grid after adding columnMagento 2 How to remove phone column in customer grid programmaticallyAdd custom column and filter to customer grid from joined table in magento 2How to add new column in custom table and also in admin listing page?how to add Custom column with link in sales order grid magentoMagento 1 - Add VAT NUMBER column in Manage Customers Grid

US F1 Visa grace period attending a conference

Don't understand notation of morphisms in Monoid definition

How to become an Editorial board member?

Is being an extrovert a necessary condition to be a manager?

What quantum phenomena violate the superposition principle in electromagnetism?

Why are logically related bit fields in MCU registers often in separate locations

Statue Park: Five

What causes a person to remain in this world as a ghost?

Gambler's Fallacy Dice

1950s or earlier book with electrical currents living on Pluto

How do you cope with rejection?

Do 'destroy' effects count as damage?

How do we explain the use of a software on a math paper?

If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?

How to use Screen Sharing if I don't know the remote Mac's IP address

Does the Aboleth have expertise in History and Perception?

How can I prevent Bash expansion from passing files starting with "-" as argument?

Department head said that group project may be rejected. How to mitigate?

Is there a realtime, uncut video of Saturn V ignition through tower clear?

Difference in 1 user doing 1000 iterations and 1000 users doing 1 iteration in Load testing

What should I wear to go and sign an employment contract?

Was Tyrion always a poor strategist?

What city and town structures are important in a low fantasy medieval world?

How would a physicist explain this starship engine?



Magento 2 - How to add a custom column in customer grid like (is approved)


Add custom column and filter to customer grid from joined table in magento 2Magento 2 - How to add a custom column in customer gridMagento 2 : Change Admin grid column widthMagento 2 Filter not working while Custom column added on Sales Grid Using Ui ComponentMagento 2.1 : how to add profit column to admin order gridMagento 2 bar disappeared in Sales Order Grid after adding columnMagento 2 How to remove phone column in customer grid programmaticallyAdd custom column and filter to customer grid from joined table in magento 2How to add new column in custom table and also in admin listing page?how to add Custom column with link in sales order grid magentoMagento 1 - Add VAT NUMBER column in Manage Customers Grid






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








1















i want to add a custom column in customer grid like "is_approved" customer section.
please suggest.










share|improve this question




























    1















    i want to add a custom column in customer grid like "is_approved" customer section.
    please suggest.










    share|improve this question
























      1












      1








      1








      i want to add a custom column in customer grid like "is_approved" customer section.
      please suggest.










      share|improve this question














      i want to add a custom column in customer grid like "is_approved" customer section.
      please suggest.







      magento-2.1 column custom-column-grid






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 9 '17 at 12:12









      Jay KapoorJay Kapoor

      186321




      186321




















          2 Answers
          2






          active

          oldest

          votes


















          0














          • First you need to create an customer attribute is_approve


          app/code/Namespace/Modulename/Setup/InstallData.php




          Note Make sure you add 'is_used_in_grid' => true, in your attribute options or you may get sql error.



          <?php 

          namespace NamespaceModulenameSetup;

          use MagentoCustomerSetupCustomerSetupFactory;
          use MagentoCustomerModelCustomer;
          use MagentoEavModelEntityAttributeSet as AttributeSet;
          use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
          use MagentoFrameworkSetupInstallDataInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;

          class InstallData implements InstallDataInterface


          /**
          * @var MagentoCustomerSetupCustomerSetupFactory
          */
          private $customerSetupFactory;

          /**
          * @var MagentoEavModelEntityAttributeSetFactor
          */
          private $attributeSetFactory;

          /**
          * Init
          *
          * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
          */
          public function __construct(
          CustomerSetupFactory $customerSetupFactory,
          AttributeSetFactory $attributeSetFactory
          )
          $this->customerSetupFactory = $customerSetupFactory;
          $this->attributeSetFactory = $attributeSetFactory;


          public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
          /** @var CustomerSetup $customerSetup */
          $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

          $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
          $attributeSetId = $customerEntity->getDefaultAttributeSetId();

          /** @var $attributeSet AttributeSet */
          $attributeSet = $this->attributeSetFactory->create();
          $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

          $customerSetup->addAttribute(Customer::ENTITY, 'is_approve', [
          'type' => 'int',
          'label' => 'Is Approved',
          'input' => 'select',
          'required' => false,
          'visible' => true,
          'user_defined' => true,
          'sort_order' => 1001,
          'position' => 1001,
          'is_used_in_grid' => true,
          'system' => 0,
          'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
          'adminhtml_only'=>1,
          'default'=>0
          ]);

          $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_approve')
          ->addData([
          'attribute_set_id' => $attributeSetId,
          'attribute_group_id' => $attributeGroupId,
          'used_in_forms' => ['adminhtml_customer'],
          ]);

          $attribute->save();




          • Display it in the customer listing create ui component


          app/code/Namespace/Modulename/view/adminhtml/ui_component/customer_listing.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">
          <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns">
          <column name="is_approve">
          <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">Is Approved</item>
          <item name="sortOrder" xsi:type="number">51</item>
          </item>
          </argument>
          </column>
          </columns>
          </listing>


          • Finally add the attribute to the customer grid index


          app/code/Namespace/Modulename/etc/indexer.xml




          <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="is_approve" xsi:type="filterable" dataType="int"/>
          </fieldset>
          </indexer>
          </config>


          • run command php bin/magento indexer:reindex and check.





          share|improve this answer























          • but i think custom attribute is not created and all my customers are not showing now

            – Jay Kapoor
            Aug 10 '17 at 5:39











          • after removing this code all customers are displaying

            – Jay Kapoor
            Aug 10 '17 at 6:00












          • Check your database if your attribute is created. Also check in logs if there are any errors found.

            – Priyank
            Aug 10 '17 at 6:00











          • check which block is getting error. There must be some typo error. It works fine for me

            – Priyank
            Aug 10 '17 at 6:01











          • which table to check in database

            – Jay Kapoor
            Aug 10 '17 at 6:11


















          1














          Here is my solution. I have created my own module. My custom attribute is from another table and another module so ihave created this module.



          https://magento.stackexchange.com/a/237030/63460






          share|improve this answer























            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%2f188508%2fmagento-2-how-to-add-a-custom-column-in-customer-grid-like-is-approved%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            • First you need to create an customer attribute is_approve


            app/code/Namespace/Modulename/Setup/InstallData.php




            Note Make sure you add 'is_used_in_grid' => true, in your attribute options or you may get sql error.



            <?php 

            namespace NamespaceModulenameSetup;

            use MagentoCustomerSetupCustomerSetupFactory;
            use MagentoCustomerModelCustomer;
            use MagentoEavModelEntityAttributeSet as AttributeSet;
            use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
            use MagentoFrameworkSetupInstallDataInterface;
            use MagentoFrameworkSetupModuleContextInterface;
            use MagentoFrameworkSetupModuleDataSetupInterface;

            class InstallData implements InstallDataInterface


            /**
            * @var MagentoCustomerSetupCustomerSetupFactory
            */
            private $customerSetupFactory;

            /**
            * @var MagentoEavModelEntityAttributeSetFactor
            */
            private $attributeSetFactory;

            /**
            * Init
            *
            * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
            */
            public function __construct(
            CustomerSetupFactory $customerSetupFactory,
            AttributeSetFactory $attributeSetFactory
            )
            $this->customerSetupFactory = $customerSetupFactory;
            $this->attributeSetFactory = $attributeSetFactory;


            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            /** @var CustomerSetup $customerSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

            $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
            $attributeSetId = $customerEntity->getDefaultAttributeSetId();

            /** @var $attributeSet AttributeSet */
            $attributeSet = $this->attributeSetFactory->create();
            $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

            $customerSetup->addAttribute(Customer::ENTITY, 'is_approve', [
            'type' => 'int',
            'label' => 'Is Approved',
            'input' => 'select',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'is_used_in_grid' => true,
            'system' => 0,
            'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
            'adminhtml_only'=>1,
            'default'=>0
            ]);

            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_approve')
            ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
            ]);

            $attribute->save();




            • Display it in the customer listing create ui component


            app/code/Namespace/Modulename/view/adminhtml/ui_component/customer_listing.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">
            <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns">
            <column name="is_approve">
            <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">Is Approved</item>
            <item name="sortOrder" xsi:type="number">51</item>
            </item>
            </argument>
            </column>
            </columns>
            </listing>


            • Finally add the attribute to the customer grid index


            app/code/Namespace/Modulename/etc/indexer.xml




            <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="is_approve" xsi:type="filterable" dataType="int"/>
            </fieldset>
            </indexer>
            </config>


            • run command php bin/magento indexer:reindex and check.





            share|improve this answer























            • but i think custom attribute is not created and all my customers are not showing now

              – Jay Kapoor
              Aug 10 '17 at 5:39











            • after removing this code all customers are displaying

              – Jay Kapoor
              Aug 10 '17 at 6:00












            • Check your database if your attribute is created. Also check in logs if there are any errors found.

              – Priyank
              Aug 10 '17 at 6:00











            • check which block is getting error. There must be some typo error. It works fine for me

              – Priyank
              Aug 10 '17 at 6:01











            • which table to check in database

              – Jay Kapoor
              Aug 10 '17 at 6:11















            0














            • First you need to create an customer attribute is_approve


            app/code/Namespace/Modulename/Setup/InstallData.php




            Note Make sure you add 'is_used_in_grid' => true, in your attribute options or you may get sql error.



            <?php 

            namespace NamespaceModulenameSetup;

            use MagentoCustomerSetupCustomerSetupFactory;
            use MagentoCustomerModelCustomer;
            use MagentoEavModelEntityAttributeSet as AttributeSet;
            use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
            use MagentoFrameworkSetupInstallDataInterface;
            use MagentoFrameworkSetupModuleContextInterface;
            use MagentoFrameworkSetupModuleDataSetupInterface;

            class InstallData implements InstallDataInterface


            /**
            * @var MagentoCustomerSetupCustomerSetupFactory
            */
            private $customerSetupFactory;

            /**
            * @var MagentoEavModelEntityAttributeSetFactor
            */
            private $attributeSetFactory;

            /**
            * Init
            *
            * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
            */
            public function __construct(
            CustomerSetupFactory $customerSetupFactory,
            AttributeSetFactory $attributeSetFactory
            )
            $this->customerSetupFactory = $customerSetupFactory;
            $this->attributeSetFactory = $attributeSetFactory;


            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            /** @var CustomerSetup $customerSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

            $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
            $attributeSetId = $customerEntity->getDefaultAttributeSetId();

            /** @var $attributeSet AttributeSet */
            $attributeSet = $this->attributeSetFactory->create();
            $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

            $customerSetup->addAttribute(Customer::ENTITY, 'is_approve', [
            'type' => 'int',
            'label' => 'Is Approved',
            'input' => 'select',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'is_used_in_grid' => true,
            'system' => 0,
            'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
            'adminhtml_only'=>1,
            'default'=>0
            ]);

            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_approve')
            ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
            ]);

            $attribute->save();




            • Display it in the customer listing create ui component


            app/code/Namespace/Modulename/view/adminhtml/ui_component/customer_listing.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">
            <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns">
            <column name="is_approve">
            <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">Is Approved</item>
            <item name="sortOrder" xsi:type="number">51</item>
            </item>
            </argument>
            </column>
            </columns>
            </listing>


            • Finally add the attribute to the customer grid index


            app/code/Namespace/Modulename/etc/indexer.xml




            <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="is_approve" xsi:type="filterable" dataType="int"/>
            </fieldset>
            </indexer>
            </config>


            • run command php bin/magento indexer:reindex and check.





            share|improve this answer























            • but i think custom attribute is not created and all my customers are not showing now

              – Jay Kapoor
              Aug 10 '17 at 5:39











            • after removing this code all customers are displaying

              – Jay Kapoor
              Aug 10 '17 at 6:00












            • Check your database if your attribute is created. Also check in logs if there are any errors found.

              – Priyank
              Aug 10 '17 at 6:00











            • check which block is getting error. There must be some typo error. It works fine for me

              – Priyank
              Aug 10 '17 at 6:01











            • which table to check in database

              – Jay Kapoor
              Aug 10 '17 at 6:11













            0












            0








            0







            • First you need to create an customer attribute is_approve


            app/code/Namespace/Modulename/Setup/InstallData.php




            Note Make sure you add 'is_used_in_grid' => true, in your attribute options or you may get sql error.



            <?php 

            namespace NamespaceModulenameSetup;

            use MagentoCustomerSetupCustomerSetupFactory;
            use MagentoCustomerModelCustomer;
            use MagentoEavModelEntityAttributeSet as AttributeSet;
            use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
            use MagentoFrameworkSetupInstallDataInterface;
            use MagentoFrameworkSetupModuleContextInterface;
            use MagentoFrameworkSetupModuleDataSetupInterface;

            class InstallData implements InstallDataInterface


            /**
            * @var MagentoCustomerSetupCustomerSetupFactory
            */
            private $customerSetupFactory;

            /**
            * @var MagentoEavModelEntityAttributeSetFactor
            */
            private $attributeSetFactory;

            /**
            * Init
            *
            * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
            */
            public function __construct(
            CustomerSetupFactory $customerSetupFactory,
            AttributeSetFactory $attributeSetFactory
            )
            $this->customerSetupFactory = $customerSetupFactory;
            $this->attributeSetFactory = $attributeSetFactory;


            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            /** @var CustomerSetup $customerSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

            $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
            $attributeSetId = $customerEntity->getDefaultAttributeSetId();

            /** @var $attributeSet AttributeSet */
            $attributeSet = $this->attributeSetFactory->create();
            $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

            $customerSetup->addAttribute(Customer::ENTITY, 'is_approve', [
            'type' => 'int',
            'label' => 'Is Approved',
            'input' => 'select',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'is_used_in_grid' => true,
            'system' => 0,
            'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
            'adminhtml_only'=>1,
            'default'=>0
            ]);

            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_approve')
            ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
            ]);

            $attribute->save();




            • Display it in the customer listing create ui component


            app/code/Namespace/Modulename/view/adminhtml/ui_component/customer_listing.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">
            <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns">
            <column name="is_approve">
            <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">Is Approved</item>
            <item name="sortOrder" xsi:type="number">51</item>
            </item>
            </argument>
            </column>
            </columns>
            </listing>


            • Finally add the attribute to the customer grid index


            app/code/Namespace/Modulename/etc/indexer.xml




            <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="is_approve" xsi:type="filterable" dataType="int"/>
            </fieldset>
            </indexer>
            </config>


            • run command php bin/magento indexer:reindex and check.





            share|improve this answer













            • First you need to create an customer attribute is_approve


            app/code/Namespace/Modulename/Setup/InstallData.php




            Note Make sure you add 'is_used_in_grid' => true, in your attribute options or you may get sql error.



            <?php 

            namespace NamespaceModulenameSetup;

            use MagentoCustomerSetupCustomerSetupFactory;
            use MagentoCustomerModelCustomer;
            use MagentoEavModelEntityAttributeSet as AttributeSet;
            use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
            use MagentoFrameworkSetupInstallDataInterface;
            use MagentoFrameworkSetupModuleContextInterface;
            use MagentoFrameworkSetupModuleDataSetupInterface;

            class InstallData implements InstallDataInterface


            /**
            * @var MagentoCustomerSetupCustomerSetupFactory
            */
            private $customerSetupFactory;

            /**
            * @var MagentoEavModelEntityAttributeSetFactor
            */
            private $attributeSetFactory;

            /**
            * Init
            *
            * @param MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory
            */
            public function __construct(
            CustomerSetupFactory $customerSetupFactory,
            AttributeSetFactory $attributeSetFactory
            )
            $this->customerSetupFactory = $customerSetupFactory;
            $this->attributeSetFactory = $attributeSetFactory;


            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            /** @var CustomerSetup $customerSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

            $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
            $attributeSetId = $customerEntity->getDefaultAttributeSetId();

            /** @var $attributeSet AttributeSet */
            $attributeSet = $this->attributeSetFactory->create();
            $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

            $customerSetup->addAttribute(Customer::ENTITY, 'is_approve', [
            'type' => 'int',
            'label' => 'Is Approved',
            'input' => 'select',
            'required' => false,
            'visible' => true,
            'user_defined' => true,
            'sort_order' => 1001,
            'position' => 1001,
            'is_used_in_grid' => true,
            'system' => 0,
            'source' => 'MagentoEavModelEntityAttributeSourceBoolean',
            'adminhtml_only'=>1,
            'default'=>0
            ]);

            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_approve')
            ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer'],
            ]);

            $attribute->save();




            • Display it in the customer listing create ui component


            app/code/Namespace/Modulename/view/adminhtml/ui_component/customer_listing.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">
            <columns name="customer_columns" class="MagentoCustomerUiComponentListingColumns">
            <column name="is_approve">
            <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">Is Approved</item>
            <item name="sortOrder" xsi:type="number">51</item>
            </item>
            </argument>
            </column>
            </columns>
            </listing>


            • Finally add the attribute to the customer grid index


            app/code/Namespace/Modulename/etc/indexer.xml




            <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="is_approve" xsi:type="filterable" dataType="int"/>
            </fieldset>
            </indexer>
            </config>


            • run command php bin/magento indexer:reindex and check.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 9 '17 at 13:21









            PriyankPriyank

            5,68242253




            5,68242253












            • but i think custom attribute is not created and all my customers are not showing now

              – Jay Kapoor
              Aug 10 '17 at 5:39











            • after removing this code all customers are displaying

              – Jay Kapoor
              Aug 10 '17 at 6:00












            • Check your database if your attribute is created. Also check in logs if there are any errors found.

              – Priyank
              Aug 10 '17 at 6:00











            • check which block is getting error. There must be some typo error. It works fine for me

              – Priyank
              Aug 10 '17 at 6:01











            • which table to check in database

              – Jay Kapoor
              Aug 10 '17 at 6:11

















            • but i think custom attribute is not created and all my customers are not showing now

              – Jay Kapoor
              Aug 10 '17 at 5:39











            • after removing this code all customers are displaying

              – Jay Kapoor
              Aug 10 '17 at 6:00












            • Check your database if your attribute is created. Also check in logs if there are any errors found.

              – Priyank
              Aug 10 '17 at 6:00











            • check which block is getting error. There must be some typo error. It works fine for me

              – Priyank
              Aug 10 '17 at 6:01











            • which table to check in database

              – Jay Kapoor
              Aug 10 '17 at 6:11
















            but i think custom attribute is not created and all my customers are not showing now

            – Jay Kapoor
            Aug 10 '17 at 5:39





            but i think custom attribute is not created and all my customers are not showing now

            – Jay Kapoor
            Aug 10 '17 at 5:39













            after removing this code all customers are displaying

            – Jay Kapoor
            Aug 10 '17 at 6:00






            after removing this code all customers are displaying

            – Jay Kapoor
            Aug 10 '17 at 6:00














            Check your database if your attribute is created. Also check in logs if there are any errors found.

            – Priyank
            Aug 10 '17 at 6:00





            Check your database if your attribute is created. Also check in logs if there are any errors found.

            – Priyank
            Aug 10 '17 at 6:00













            check which block is getting error. There must be some typo error. It works fine for me

            – Priyank
            Aug 10 '17 at 6:01





            check which block is getting error. There must be some typo error. It works fine for me

            – Priyank
            Aug 10 '17 at 6:01













            which table to check in database

            – Jay Kapoor
            Aug 10 '17 at 6:11





            which table to check in database

            – Jay Kapoor
            Aug 10 '17 at 6:11













            1














            Here is my solution. I have created my own module. My custom attribute is from another table and another module so ihave created this module.



            https://magento.stackexchange.com/a/237030/63460






            share|improve this answer



























              1














              Here is my solution. I have created my own module. My custom attribute is from another table and another module so ihave created this module.



              https://magento.stackexchange.com/a/237030/63460






              share|improve this answer

























                1












                1








                1







                Here is my solution. I have created my own module. My custom attribute is from another table and another module so ihave created this module.



                https://magento.stackexchange.com/a/237030/63460






                share|improve this answer













                Here is my solution. I have created my own module. My custom attribute is from another table and another module so ihave created this module.



                https://magento.stackexchange.com/a/237030/63460







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 3 '18 at 6:11









                Ankit8Ankit8

                889




                889



























                    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%2f188508%2fmagento-2-how-to-add-a-custom-column-in-customer-grid-like-is-approved%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?