{"id":611,"date":"2019-09-25T14:25:07","date_gmt":"2019-09-25T14:25:07","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/25\/add-custom-column-in-magento-2-products-grid\/"},"modified":"2025-06-16T13:04:28","modified_gmt":"2025-06-16T07:34:28","slug":"add-custom-column-in-magento-2-products-grid","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-custom-column-in-magento-2-products-grid\/","title":{"rendered":"How to Add a Custom Column in Magento 2 Products Grid"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The default Magento 2 product grid makes it easy to add a column for displaying values for any product attribute. As they are already available under column control of the products grid toolbar. You just need to tick the check\/uncheck for that product attribute under Columns control to show\/hide values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, to add a custom column in Magento 2 product grid\u00a0that is not a product attribute is not supported by default Magento 2. You need to apply the below solution to add custom columns like stock, quantity, website or any data that is not a product attribute. Along with <a href=\"https:\/\/meetanshi.com\/blog\/add-category-column-to-product-grid-in-magento-2\/\" data-type=\"link\" data-id=\"https:\/\/meetanshi.com\/blog\/add-category-column-to-product-grid-in-magento-2\/\">Category Column to Product Grid<\/a>, you can also add action column in admin grid in Magento 2 that enables you to perform record specific actions like editing and deleting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">More organized the data, easier it will be for the admin to manage the products.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Add a Custom Column in Magento 2 Products Grid:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create <strong>registration.php<\/strong> file in <strong><strong>app\\code\\[Vendor]\\[Namespace]\\<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n        \\Magento\\Framework\\Component\\ComponentRegistrar::register(\n            \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n            '[Vendor]_[Namespace]',\n            __DIR__\n    );<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create <strong>module.xml<\/strong> file in <strong><strong>app\\code\\[Vendor]\\[Namespace]\\etc<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;?xml version=\"1.0\"?>\n    &lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\">\n        &lt;module name=\"[Vendor]_[Namespace]\" setup_version=\"1.0.0\"\/>\n    &lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create <strong>product_listing.xml<\/strong> file in <strong><strong>app\\code\\[Vendor]\\[Namespace]\\adminhtml\\ui_component<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;?xml version=\"1.0\"?>\n\n    &lt;listing xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd\">\n        &lt;columns name=\"product_columns\">\n               &lt;column name=\"stock_status\" component=\"Magento_Ui\/js\/grid\/columns\/select\" sortOrder=\"76\">\n                      &lt;settings>\n                            &lt;addField>true&lt;\/addField>\n                            &lt;options class=\"Magento\\Config\\Model\\Config\\Source\\Yesno\"\/>\n                            &lt;filter>select&lt;\/filter>\n                            &lt;dataType>select&lt;\/dataType>\n                            &lt;sortable>false&lt;\/sortable>\n                            &lt;label translate=\"true\">Stock Status&lt;\/label>\n                     &lt;\/settings>\n               &lt;\/column>\n         &lt;\/columns>\n    &lt;\/listing><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create <strong>di.xml<\/strong> file in <strong><strong>app\\code\\[Vendor]\\[Namespace]\\etc\\adminhtml<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;?xml version=\"1.0\" encoding=\"utf-8\" ?>\n    &lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n             &lt;type name=\"Magento\\Catalog\\Ui\\DataProvider\\Product\\ProductDataProvider\">\n                  &lt;arguments>\n                       &lt;argument name=\"addFieldStrategies\" xsi:type=\"array\">\n                            &lt;item name=\"stock_status\" xsi:type=\"object\">[Vendor]\\[Namespace]\\Ui\\DataProvider\\Product\\AddCustomField&lt;\/item>\n                       &lt;\/argument>\n                 &lt;\/arguments>\n             &lt;\/type>\n    &lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Create <strong>AddCustomField.php<\/strong> file in <strong><strong>app\\code\\[Vendor]\\[Namespace]\\Ui\\DataProvider\\Product\\<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;?php\n    namespace [Vendor]\\[Namespace]\\Ui\\DataProvider\\Product;\n    class AddCustomField implements \\Magento\\Ui\\DataProvider\\AddFieldToCollectionInterface\n    {\n        public function addField(\\Magento\\Framework\\Data\\Collection $collection, $field, $alias = null){\n            $collection->joinField(\n                'stock_status',\n                'cataloginventory_stock_status',\n                'stock_status',\n                'product_id=entity_id',\n                null,\n                'left'\n            );\n        }\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also likewise you can <a href=\"https:\/\/meetanshi.com\/blog\/include-custom-column-in-export-to-csv-in-magento-2\/\">add custom column in export to csv in Magento 2<\/a> to have an csv with custom changes made in it. Likewise you can also <a href=\"https:\/\/meetanshi.com\/blog\/add-image-thumbnail-column-in-magento-2-admin-ui-grid\/\">display image thumbnail column<\/a> in Magento 2 admin UI grid.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with fellow developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default Magento 2 product grid makes it easy to add a column for displaying values for any product attribute. As they are already available&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-611","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"predecessor-version":[{"id":16875,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions\/16875"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}