2

I need to add custom column in admin sales_order_view for each item listing with the help of renderer. For example, there are some predefined columns like name, status, price, qty, discount etc are in order item listing. I need to order custom column in that listing.

1 Answer 1

8

Assuming you have created 'custom_item_column' in sales_order_item table you can add a custom column to Items Grid in sales order view by following:

1.Create sales_order_view.xml file in app/code/[Vendor]/[Modulename]/view/adminhtml/layout folder and add the below code.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="order_items"> <arguments> <argument name="columns" xsi:type="array"> <item name="custom_item_column" xsi:type="string" translate="true">Custom Item Column</item> </argument> </arguments> <referenceBlock name="default_order_items_renderer"> <arguments> <argument name="columns" xsi:type="array"> <item name="custom_item_column" xsi:type="string" translate="true">col-custom_item_column</item> </argument> </arguments> </referenceBlock> <block class="Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn" name="column_custom_item_column" template="Namespace_Modulename::custom_item_column.phtml" group="column" /> </referenceBlock> </body> 

2.Create "custom_item_column.phtml" file in [Namespace]/[Modulename]/view/adminhtml/templates folder and add the below code.

<span><?= /* @escapeNotVerified */ __($block->getItem()->getData('custom_item_column')) ?></span> 

source : https://github.com/magento/magento2/pull/11076

6
  • Thanks @Aziz for the answer. You saved my day. Commented Nov 19, 2019 at 14:33
  • @aziz i tried this way but it is not displyaing Commented Apr 23, 2020 at 7:55
  • @Sabareesh This works fine for me, please check the steps again. Maybe you are missing something Commented Apr 26, 2020 at 5:23
  • @Aziz I tried this on Magento 2.3.4 as well and it is not rendering the column data. I have followed your example exactly. The template for column_custom_item_column block is never rendered. Commented May 8, 2020 at 20:55
  • Can I add it after the original price ? Commented Jan 6, 2021 at 7:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.