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.
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>
-
-
-
@Sabareesh This works fine for me, please check the steps again. Maybe you are missing something – Aziz Apr 26 '20 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. – DaChronDon May 8 '20 at 20:55
-