{"id":571,"date":"2019-08-28T06:35:09","date_gmt":"2019-08-28T06:35:09","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/08\/28\/add-custom-column-in-order-grid-in-magento-2\/"},"modified":"2025-05-22T16:05:21","modified_gmt":"2025-05-22T10:35:21","slug":"add-custom-column-in-order-grid-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-custom-column-in-order-grid-in-magento-2\/","title":{"rendered":"How to Add a Custom Column in Order Grid in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The default Magento 2 sales order grid offers a number of columns to easily manage the order processing. However, with the advancing E-commerce options and the majority of preference for online shopping, more data is to be handled, for which, the default order grid may not be enough.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The smooth order process is essential when it comes to customer experience. If the store can handle the order delivery fast and accurate, the customers are prompted to repeat their choice for the next purchase too!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, it is possible only when the admin can systematically handle the order data. All the data accessible in one place can make it easier. For that, the admin may need to add a custom column in order grid in Magento 2 store which is not offered by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The programmatic method to add a custom column in the sales order grid in Magento 2 store is given in the post. You can also add <a title=\"How to Add Action Column in Admin Grid in Magento 2 \u2013 The Complete Method\" href=\"https:\/\/meetanshi.com\/blog\/how-to-add-action-column-in-admin-grid-in-magento-2\/\">action column in Magento 2 admin grid<\/a> as the action column enables you to perform record-specific actions such as deleting or editing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, you can also opt for easy solution, the <a href=\"https:\/\/meetanshi.com\/magento-2-custom-order-grid.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Custom Order Grid<\/a> extension that allows adding 50+ custom columns in the order grid for the easy and accurate order processing system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to add a custom column in order grid in Magento 2 \u200b\u200b\u200b\u200b\u200b\u200b:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create <i><strong>di.xml<\/strong><\/i> file at <strong><strong><strong>app\\code\\Vendor\\Module\\etc\\<\/strong><\/strong><\/strong> with following code:<\/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:ObjectManager\/etc\/config.xsd\">\n    &lt;type name=\"Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\CollectionFactory\">\n        &lt;arguments>\n            &lt;argument name=\"collections\" xsi:type=\"array\">\n                &lt;item name=\"sales_order_grid_data_source\" xsi:type=\"string\">Vendor\\Module\\Model\\ResourceModel\\Order\\Grid\\Collection&lt;\/item>\n            &lt;\/argument>\n        &lt;\/arguments>\n    &lt;\/type>\n    &lt;type name=\"Vendor\\Module\\Model\\ResourceModel\\Order\\Grid\\Collection\">\n        &lt;arguments>\n            &lt;argument name=\"mainTable\" xsi:type=\"string\">sales_order_grid&lt;\/argument>\n            &lt;argument name=\"resourceModel\" xsi:type=\"string\">Magento\\Sales\\Model\\ResourceModel\\Order&lt;\/argument>\n        &lt;\/arguments>\n    &lt;\/type>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create <strong>Collection.php<\/strong> file at <strong><strong>app\\code\\Vendor\\Module\\Model\\ResourceModel\\Order\\Grid\\<\/strong><\/strong> with the following code:<\/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\nnamespace Vendor\\Module\\Model\\ResourceModel\\Order\\Grid;\n\nuse Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface as FetchStrategy;\nuse Magento\\Framework\\Data\\Collection\\EntityFactoryInterface as EntityFactory;\nuse Magento\\Framework\\Event\\ManagerInterface as EventManager;\nuse Magento\\Sales\\Model\\ResourceModel\\Order\\Grid\\Collection as OriginalCollection;\nuse Psr\\Log\\LoggerInterface as Logger;\n\n\/**\n * Order grid extended collection\n *\/\nclass Collection extends OriginalCollection\n{\n    protected $helper;\n\n    public function __construct(\n        EntityFactory $entityFactory,\n        Logger $logger,\n        FetchStrategy $fetchStrategy,\n        EventManager $eventManager,\n        $mainTable = 'sales_order_grid',\n        $resourceModel = \\Magento\\Sales\\Model\\ResourceModel\\Order::class\n    )\n    {\n        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);\n    }\n\n    protected function _renderFiltersBefore()\n    {\n        $joinTable = $this->getTable('sales_order');\n        $this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = sales_order.entity_id', ['tax_amount', 'discount_amount', 'coupon_code']);\n        parent::_renderFiltersBefore();\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create&nbsp;<em><strong>sales_order_grid.xml<\/strong><\/em> file <strong><strong>app\\code\\Vendor\\Module\\view\\adminhtml\\ui_component\\<\/strong><\/strong> with following code:<\/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;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=\"sales_order_columns\">\n        &lt;column name=\"tax_amount\" class=\"Magento\\Sales\\Ui\\Component\\Listing\\Column\\PurchasedPrice\">\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"filter\" xsi:type=\"string\">textRange&lt;\/item>\n                    &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Tax Amount&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n        &lt;\/column>\n        &lt;column name=\"discount_amount\" class=\"Magento\\Sales\\Ui\\Component\\Listing\\Column\\PurchasedPrice\">\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"filter\" xsi:type=\"string\">textRange&lt;\/item>\n                    &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Discount Amount&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n        &lt;\/column>\n        &lt;column name=\"coupon_code\">\n            &lt;argument name=\"data\" xsi:type=\"array\">\n                &lt;item name=\"config\" xsi:type=\"array\">\n                    &lt;item name=\"filter\" xsi:type=\"string\">text&lt;\/item>\n                    &lt;item name=\"label\" xsi:type=\"string\" translate=\"true\">Coupon Code&lt;\/item>\n                &lt;\/item>\n            &lt;\/argument>\n        &lt;\/column>\n    &lt;\/columns>\n&lt;\/listing><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. Also you can <a href=\"https:\/\/meetanshi.com\/blog\/include-custom-column-in-export-to-csv-in-magento-2\/\">include custom column in export to csv in Magento 2<\/a> it will helpful to you when you want csv with custom made changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also <a href=\"https:\/\/meetanshi.com\/blog\/display-product-image-in-order-create-page-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">add custom column to display product image in order create page<\/a> and make order creation process seamless!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the above solution with fellow developers on social media. You can also learn to <a href=\"https:\/\/meetanshi.com\/blog\/create-order-in-magento-2-admin-panel\/\">create order in admin panel<\/a> Magento 2 to assist your customers while placing orders when they require.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default Magento 2 sales order grid offers a number of columns to easily manage the order processing. However, with the advancing E-commerce options and&#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-571","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/571","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=571"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/571\/revisions"}],"predecessor-version":[{"id":15291,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/571\/revisions\/15291"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}