magento 2 add company column to sale order invoice grid in backend
If you want add a custom column to sale order invoice grid, you need set value for column in data soruce of ui component.
So here is an example: how to add company column to sale order invoice grid in backend ?
1. Add “company” column to sales_order_invoice_grid in view.
<?xml version="1.0" encoding="UTF-8"?><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="company"><argument name="data" xsi:type="array"><item name="config" xsi:type="array"><item name="filter" xsi:type="string">text</item><item name="dataType" xsi:type="string">text</item><item name="label" xsi:type="string" translate="true">Company</item><item name="sortOrder" xsi:type="number">70</item></item></argument></column></columns></listing>
2. Create di.xml for “company” value where to get.
<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"><arguments><argument name="collections" xsi:type="array"><item name="sales_order_invoice_grid_data_source" xsi:type="string">Tony\InvoiceCompanyColumn\Model\ResourceModel\Order\Invoice\Grid\Collection</item></argument></arguments></type></config>
3. Write some logic to model.
protected function _renderFiltersBefore(){$joinTable = $this->getTable('sales_order_address');$this->getSelect()->joinLeft($joinTable,'main_table.order_id = sales_order_address.parent_id AND sales_order_address.address_type = "billing"',['company']);parent::_renderFiltersBefore();}
After completing above steps you will see a new column named “company” will show in sale order invoice grid.