1

How may i add column to Sales -> Invoices grid?

0

This solution may be a bit more efficient and 100% tested working since it follows the native way of adding a column to the grid, and you won't have to load every order displayed on the page to obtain the column data (utilising the sales_invoice_grid table instead). The above is a great example of how to create a customised renderer though.

app/code/[vendor]/[package]/view/adminhtml/ui_component/sales_order_invoice_grid.xml

<!-- Add the column "custom_column" (Custom Column) to the sales invoice grid. -->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_invoice_columns">
    <column name="custom_column">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Custom Column</item>
            </item>
        </argument>
    </column>
</columns>

Please note that you must enable the column using the drop-down widget above the invoice grid before it appears.

app/code/[vendor]/[package]/etc/di.xml

<!-- Sync the column "custom_column" between the sales_invoice and sales_invoice_grid tables -->
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid">
    <arguments>
        <argument name="columns">
            <item name="custom_column" xsi:type="string">sales_invoice.custom_column</item>
        </argument>
    </arguments>
</virtualType>

Sample setup code to add column to sales_invoice_grid table (use this in your install/upgrade script). The same code works for the sales_invoice table by the way.

$setup->getConnection()->addColumn(
        $setup->getTable('sales_invoice_grid'),
        'custom_column',
        [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            'length' => 255,
            'nullable' => true,
            'comment' => 'Custom Column'
        ]
    );

For details information. Please check Add column in Sales Invoice/Order grid in Magento 2

Hope it helps you! :-)

| improve this answer | |
  • how where you able to get this filtered? – xhallix Apr 30 '17 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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