0

I created, with InstallData.php, a custom product attribute, with the right options so I can see it in the columns in the catalog product list.

However, is there a way to make it displayed in the grid without to have to select it in the columns list?

 $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'special_percentage',
                [
                    'type' => 'decimal',
                    'label' => 'Discount percentage',
                    'input' => 'text',
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'default' => 0,
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_on_front' => false,
                    'used_in_product_listing' => true,
                    'is_used_in_grid' => true,
                    'is_filterable_in_grid' => true,
                    'unique' => false,
                    'apply_to' => '',
                    'group' => 'General',
                    'system' => true,
                    'show_in_grid' => true
                ]
            );
1
  • I have added a custom attribute(Name: Warehouse, along with three values) on my sales order grid. if order placed I need able to edit that attribute values, like eg. this order assigned for this warehouse like that. is possible can i edit what i need? source : magento.stackexchange.com/q/196004/57334
    – zus
    Commented Oct 12, 2017 at 12:15

3 Answers 3

3

You can try to replace 'show_in_grid' => true with

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

and maybe 'is_filterable_in_grid' => true if you want it filtering.

1
  • Same thing. I tried with another custom attribute, already set-up, and changed these values in the DB. Same result: it adds it to the list of column but not display it directly, I have to select it. May be its not possible.
    – enrico69
    Commented Jan 27, 2017 at 9:33
1

have a look at the catalog_eav_attribute table in your database.

I think it should have a column like show_in_grid or something similar.

You can add this to the array when creating the attribute. Setting it to 1 or true should then automatically show the attribute in the products grid.

For example, if the column is show_in_grid:

$eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'test_attribute',
            [
                'type' => 'int',
                'backend' => '',
                'frontend' => '',
                'label' => 'Test Attribute',
                'input' => '',
                'class' => '',
                'source' => '',
                'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => 0,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => '',
                'show_in_grid' => true
            ]
        );
1
  • Infortunately, that's not working, I still have to check it in the columns list. I will add my code in the question.
    – enrico69
    Commented Jan 27, 2017 at 8:07
1

Try this option

'is_used_in_grid'=>1

I have tested in Magento2.0.8 it works fine.

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.