cancel
Showing results for 
Search instead for 
Did you mean: 

[Magento2.2]Show a custom attribute in Customer table in administration template

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

[Magento2.2]Show a custom attribute in Customer table in administration template

So, i already have created my custom attributes in the InstallData.php file, i now need to show some of them on the Customer table in the admin area of the website. The attributes i need to display are of the varchar type in the database, below is the code i used to create one of the custom attributes. 

 

$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'codice_fiscale', [
            'type' => 'varchar',
            'label' => 'codice fiscale',
            'input' => 'text',
            'source' => '',
            'required' => false,
            'visible' => true,
            'position' => 333,
            'system' => false,
            'backend' => ''
        ]);


        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'codice_fiscale')
            ->addData(['used_in_forms' => [
                'adminhtml_customer',
                'adminhtml_checkout',
                'customer_account_create',
                'customer_account_edit'
            ]]);
        $attribute->save();

I've tried some options i found on the web but nothing worked 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

11 REPLIES 11

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

Sorry with customer table do you mean customer grid?

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

@franconicolas 

 

Yes, the one that shows all the customers in the admin area 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

Good, so you should put all these flags on "1" is_used_on_grid, is_visible_in_grid, is_filterable_in_grid, is_searchable_in_grid check customer_eav_attribute table, then you will see your attribute on "Columns" button to add dynamically on the grid.

 

 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

@franconicolas 

 

i've checked that table in the database but i don't have a record for my custom attributes there, should i add it manually using the correct attribute_id of the attributes i want to add? 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

@daniel_bertagnolli if you don't see your attribute there something wrong with your create script, did you face some error when run setup:upgrade command?

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

@franconicolas 

 

the script ran fine and the attributes have been created, i can find them in the eav_attribute table but not in the table you mentioned 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

Still not working, anyone got an idea please? 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

Create YourNamespace/YourModule/view/base/ui_component/customer_form.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="codice_fiscale" formElement="input">
            <settings>
                <visible>true</visible>
            </settings>
        </field>
    </fieldset>
</form>

 Hope this will help you.if yes then,Click Kudos & Accept as Solution

 

Re: [Magento2.2]Show a custom attribute in Customer table in administration template

Hi @RanjeetBhojwani ,

 

sorry for not answering sooner, i've tried your solution but it's still not showing the new column.

Ofcourse i ran setup:upgrade, cache:clean and cache:flush before testing it