2

i added custom columns in Sales Order Grid successfully, but when i export data in CSV file the custom column blanked

<?php
namespace Vender\Module\Ui\Component\Listing\Column;

use \Magento\Sales\Api\OrderRepositoryInterface;
use \Magento\Framework\View\Element\UiComponent\ContextInterface;
use \Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
use \Magento\Framework\Api\SearchCriteriaBuilder;

class CGST extends Column
{
    protected $_orderRepository;
    protected $_searchCriteria;

    public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, OrderRepositoryInterface $orderRepository, SearchCriteriaBuilder $criteria, array $components = [], array $data = [])
    {
        $this->_orderRepository = $orderRepository;
        $this->_searchCriteria  = $criteria;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }

    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {

                $order  = $this->_orderRepository->get($item["entity_id"]);
                $export_status = $order->getData("cgst");

                $item[$this->getData('name')] = $export_status;
            }
        }

        return $dataSource;
    }
}

and here is my xml file

<?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_columns">
        <column name="cgst" class="Vender\Module\Ui\Component\Listing\Column\CGST">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="string">true</item>
                    <item name="label" xsi:type="string" translate="true">CGST</item>
                </item>
            </argument>
        </column>

    </columns>
</listing>
1
  • hello can you send me complete set of module, i have same issue. irshad.ahmad@iflair.com
    – irshad
    Jan 7, 2020 at 8:38

1 Answer 1

2

For export functionality /vendor/magento/module-ui/Model/Export/ is responsible to export data. so you need to look in to this core file and override below two file and customize as per your requirement.

/vendor/magento/module-ui/Model/Export/ConvertToCsv.php

And

/vendor/magento/module-ui/Model/Export/ConvertToXml.php

Then, you need to add custom code on function getCsvFile()

And you need to add SKU column to sales order grid to render data.

For reference Check this link

I hope it helps!

Your Answer

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

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