I succesfully added some custom fields on Sales Order Grid.

If I export "Excel XML" is working fine but with "CSV" custom fields are blank.

I have compared the following files:




Both files get items collecction in the same way:


$searchResult = $component->getContext()->getDataProvider()->getSearchResult();
$searchResultItems = $searchResult->getItems();



$dataProvider = $component->getContext()->getDataProvider();
$items = $dataProvider->getSearchResult()->getItems();

But the second one seems not joining the custom tables defined in Module plugin:

public function aroundGetReport(
    \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $subject,
    \Closure $proceed,
) {
    $result = $proceed($requestName);
    if ($requestName == 'sales_order_grid_data_source') {
        if ($result instanceof $this->collection
        ) {
                $select = $this->collection->getSelect();
                    ['soi' => 'sales_order_item'],
                    'soi.order_id = main_table.entity_id',
                    'items_skus'  => new \Zend_Db_Expr('group_concat(soi.sku SEPARATOR ",")'),
                    'items_names' => new \Zend_Db_Expr('group_concat(soi.name SEPARATOR ",")')
                    ['soa' => 'sales_order_address'],
                    'main_table.entity_id = soa.parent_id',
                    ['bill_to_country' => 'country_id']
                    ['bot' => 'bileamara_order_tickets'],
                    'bot.order_id = main_table.entity_id',
                    ['has_ticket' => 'bot.nr_tickets']
                $select->where('`soa`.address_type = "billing" AND `soi`.product_type = "simple"');


                $this->registry->register('cc_added', true);

                return $this->collection;
    return $result;

In fact, when I try to export the CSV by filtering through a custom field, I get the following error:

Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'has_ticket' in 'where clause', query was: SELECT COUNT(*) FROM `sales_order_grid` AS `main_table` WHERE (`has_ticket` = '1') AND (`has_ticket` = '1')

Why Magento\Ui\Model\Export\ConvertToCSV dont't get joined tables like Magento\Ui\Model\Export\ConvertToXml?

  • Hello @krybbio i want to add one custom filed of comment history in order export can u help me..? Commented May 14, 2020 at 10:28
  • @ShanHaider you need to add your custom field in grid an then use the same logic in aroundGetReport. Pay attention to the answer in this post: return $this->collection; must be located outside the if statment.
    – krybbio
    Commented May 14, 2020 at 15:42

1 Answer 1


In my case the problem was in plugin aroundGetReport since i use $this->registry->registry('cc_added') check.

Magento\Ui\Model\Export\ConvertToCSV calls $dataProvider->getSearchResult() more than once, so only the first one get the joined collection.

Move the return $this->collection; out of the if(is_null($this->registry->registry('cc_added'))) condition solve the issue.

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.