{"id":52373,"date":"2016-06-17T16:01:15","date_gmt":"2016-06-17T16:01:15","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=52373"},"modified":"2024-02-22T11:04:15","modified_gmt":"2024-02-22T11:04:15","slug":"add-column-existing-grid-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/","title":{"rendered":"Add Column in Existing Grid in Magento 2"},"content":{"rendered":"\n<p>To add a column in an existing grid in magento2, you can follow the following process:<\/p>\n\n\n\n<p>Firstly, create a ui_component XML\u00a0file with the same name that is used in the existing grid.<\/p>\n\n\n\n<p>\/app\/code\/Webkul\/Test\/view\/adminhtml\/ui_component\/add_column_example.xml<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;listing xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Ui:etc\/ui_configuration.xsd&quot;&gt;\n    &lt;columns name=&quot;test_attribute_columns&quot;&gt;\n        &lt;column name=&quot;attributename&quot; class=&quot;Webkul\\Test\\Ui\\Component\\Listing\\Column\\ShowAttrAction&quot;&gt;\n            &lt;argument name=&quot;data&quot; xsi:type=&quot;array&quot;&gt;\n                &lt;item name=&quot;config&quot; xsi:type=&quot;array&quot;&gt;\n                    &lt;item name=&quot;sortable&quot; xsi:type=&quot;boolean&quot;&gt;false&lt;\/item&gt;\n                    &lt;item name=&quot;label&quot; xsi:type=&quot;string&quot; translate=&quot;true&quot;&gt;AttributeName&lt;\/item&gt;\n                    &lt;item name=&quot;sortOrder&quot; xsi:type=&quot;number&quot;&gt;1&lt;\/item&gt;\n                &lt;\/item&gt;\n            &lt;\/argument&gt;\n        &lt;\/column&gt;\n    &lt;\/columns&gt;\n&lt;\/listing&gt;<\/pre>\n\n\n\n<p>Here,<br>The field &#8220;name&#8221; of &lt;columns> tag should be the same as used in the existing grid.<br>The field &#8220;class&#8221; of &lt;column> tag contains the class name in which we define the values for that column.<br>Field &#8220;label&#8221; of &lt;item> tag used for column name which you want to display on heading.<br>Field &#8220;sortOrder&#8221; of &lt;item> tag used for sort number for the field.<\/p>\n\n\n\n<p>Now, create app\/code\/Webkul\/Test\/Ui\/Component\/Listing\/Column\/ShowAttrAction.php<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\Test\\Ui\\Component\\Listing\\Column;\n \nuse Magento\\Framework\\View\\Element\\UiComponent\\ContextInterface;\nuse Magento\\Framework\\View\\Element\\UiComponentFactory;\nuse Magento\\Ui\\Component\\Listing\\Columns\\Column;\n \nclass ShowAttrAction extends Column\n{\n    \/**\n     * \n     * @param ContextInterface   $context           \n     * @param UiComponentFactory $uiComponentFactory   \n     * @param array              $components        \n     * @param array              $data              \n     *\/\n    public function __construct(\n        ContextInterface $context,\n        UiComponentFactory $uiComponentFactory,\n        array $components = &#091;],\n        array $data = &#091;]\n    ) {\n        parent::__construct($context, $uiComponentFactory, $components, $data);\n    }\n \n    \/**\n     * Prepare Data Source\n     *\n     * @param array $dataSource\n     * @return array\n     *\/\n    public function prepareDataSource(array $dataSource)\n    {\n        if (isset($dataSource&#091;&#039;data&#039;]&#091;&#039;items&#039;])) {\n            foreach ($dataSource&#091;&#039;data&#039;]&#091;&#039;items&#039;] as &amp; $item) {\n                $item&#091;$this-&gt;getData(&#039;name&#039;)] = 1;\/\/Value which you want to display\n            }\n        }\n        return $dataSource;\n    }\n}<\/pre>\n\n\n\n<p>Here, $dataSource returns the array which includes values for your field.<br>$this->getData(&#8216;name&#8217;) is the value that you passed in the name field of &lt;column> tag.<\/p>\n\n\n\n<p>After this, your column is visible in the grid.<\/p>\n\n\n\n<p>I hope this blog will help you with Add Columns to the existing grid in Magento 2. You may also check our wide range of best\u00a0<a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Extensions<\/a>.<\/p>\n\n\n\n<p>Please reach out to our team via a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">support ticket<\/a>&nbsp;if you have any queries.<\/p>\n\n\n\n<p>Try this and if you have any queries then just comment below \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To add a column in an existing grid in magento2, you can follow the following process: Firstly, create a ui_component XML\u00a0file with the same name that is used in the existing grid. \/app\/code\/Webkul\/Test\/view\/adminhtml\/ui_component\/add_column_example.xml Here,The field &#8220;name&#8221; of &lt;columns> tag should be the same as used in the existing grid.The field &#8220;class&#8221; of &lt;column> tag contains <a href=\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[2070],"class_list":["post-52373","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add Column in Existing Grid in Magento 2<\/title>\n<meta name=\"description\" content=\"In this blog we will discuss add Column in Existing Grid in Magento 2\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Column in Existing Grid in Magento 2\" \/>\n<meta property=\"og:description\" content=\"In this blog we will discuss add Column in Existing Grid in Magento 2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-17T16:01:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-22T11:04:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bulbul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bulbul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\"},\"author\":{\"name\":\"Bulbul\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\"},\"headline\":\"Add Column in Existing Grid in Magento 2\",\"datePublished\":\"2016-06-17T16:01:15+00:00\",\"dateModified\":\"2024-02-22T11:04:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\"},\"wordCount\":226,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Magento2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\",\"name\":\"Add Column in Existing Grid in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2016-06-17T16:01:15+00:00\",\"dateModified\":\"2024-02-22T11:04:15+00:00\",\"description\":\"In this blog we will discuss add Column in Existing Grid in Magento 2\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Add Column in Existing Grid in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\",\"name\":\"Bulbul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Bulbul\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/bulbul896\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add Column in Existing Grid in Magento 2","description":"In this blog we will discuss add Column in Existing Grid in Magento 2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/","og_locale":"en_US","og_type":"article","og_title":"Add Column in Existing Grid in Magento 2","og_description":"In this blog we will discuss add Column in Existing Grid in Magento 2","og_url":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-06-17T16:01:15+00:00","article_modified_time":"2024-02-22T11:04:15+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Bulbul","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Bulbul","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/"},"author":{"name":"Bulbul","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e"},"headline":"Add Column in Existing Grid in Magento 2","datePublished":"2016-06-17T16:01:15+00:00","dateModified":"2024-02-22T11:04:15+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/"},"wordCount":226,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Magento2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/","url":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/","name":"Add Column in Existing Grid in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2016-06-17T16:01:15+00:00","dateModified":"2024-02-22T11:04:15+00:00","description":"In this blog we will discuss add Column in Existing Grid in Magento 2","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-column-existing-grid-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Add Column in Existing Grid in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e","name":"Bulbul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Bulbul"},"url":"https:\/\/webkul.com\/blog\/author\/bulbul896\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/52373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=52373"}],"version-history":[{"count":14,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/52373\/revisions"}],"predecessor-version":[{"id":423826,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/52373\/revisions\/423826"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=52373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=52373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=52373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}