I have a column in sales_order table. I want to show this column in all grids in admin side.

I have already shown it in sales_order_gdir. But couldn't find it on sales_invoice grid, sales_shippment_grid and sales_creditmemo_grid.

Please help.

1 Answer 1


You have to create virtual type for the grid and also need to create join query for the table join.

Please follow guide for more reference :- https://amasty.com/knowledge-base/how-to-add-a-custom-column-to-the-order-grid-in-magento-2.html

Below is detailed answer steps :-

Step 1:- Create ResourceModel for your field join in your custom module.

in the _renderFiltersBefore method, you can add the columns that you want, for example, we’ve used the discount_amount column. In this array, you can pass as many parameters from the sales_order table as you like. Also, here you can join the other one or several tables to use the needed parameters for the order.


namespace Vendor\Module\Model\ResourceModel\Order\Grid;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Sales\Model\ResourceModel\Order;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OrderGridCollection;
use Psr\Log\LoggerInterface as Logger;

class Collection extends OrderGridCollection
    public function __construct(
        EntityFactory $entityFactory,
        Logger $logger,
        FetchStrategy $fetchStrategy,
        EventManager $eventManager,
        $mainTable = 'sales_order_grid',
        $resourceModel = Order::class
    ) {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
    protected function _renderFiltersBefore() {
        $joinTable = $this->getTable('sales_order'); // ADD YOUR TABLE NAME 
            ['sales_order_table' => $joinTable],
            'main_table.entity_id = sales_order_table.entity_id',
            ['discount_amount'] // you can add other attributes here

Step 2:- Create a ui grid file in your view directly.

For invoice grid create below file.


In the ui grid file you have to define your column name and datasource.

For the data source file you can review core Magento class and make your own class accordingly.


<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <columns name="sales_order_invoice_columns"> /* Here you have to add columns name as per define in the ui component file */
        <column name="discount_amount" class="Magento\Sales\Ui\Component\Listing\Column\PurchasedPrice"> /* Here you can pass your own class (datasource) and you can return data as per your logic */
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="label" xsi:type="string" translate="true">Discount Amount</item>

Step 3:- Create di.xml and define virtual type for it.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
            <argument name="collections" xsi:type="array">
                <item name="sales_order_grid_data_source" 
xsi:type="string">Vendor\Module\Model\ResourceModel\Order\Grid\Collection</item> /* Add your ResourceModel class here */
    <type name="Vendor\Module\Model\ResourceModel\Order\Grid\Collection">
            <argument name="mainTable" xsi:type="string">sales_invoice</argument> /* Pass here main table name which is responsible for the data return */
            <argument name="resourceModel" xsi:type="string">Magento\Sales\Model\ResourceModel\Order\Invoice\Grid</argument>/* Pass here ResourceModel for the particular grid */

Save files and clean the cache.

I hope this will help you.

  • Please enlighten me further. No idea how to do this. That Amasty solution I have already tried . worked for sales_order_grid, not for sales_invoice_grid . Commented Jan 3, 2023 at 9:54
  • Hello @JasvirSingh, I have updated the answer, please take a look on it. Commented Jan 4, 2023 at 8:05
  • Hello @JasvirSingh , is it works for you ? Commented Jan 5, 2023 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.