Skip to content

Issue with exporting custom column(s) to Excel XML

This a Category.php in UiComponentListingColumn in a child module

public function prepareDataSource(array $dataSource)
    {
        $fieldName = $this->getData('name');
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                //print_r($item);die;
                if (isset($item['product_id'])) {
                    $product = $this->_productloader->create()->load($item['product_id']);
                    $cats = $product->getCategoryIds();
                    $objectManager   = MagentoFrameworkAppObjectManager::getInstance();
                    $categories = [];

                    if(count($cats) ){
                        foreach($cats as $cat){
                            $category = $objectManager->create('MagentoCatalogModelCategory')->load($cat);
                            $categories[] = $category->getName();
                        }

                    }
                    $item[$fieldName] = implode(',',$categories);
                }

            }
        }
        return $dataSource;
    }

It shows the proper category names in the UI grid.
When I export it, Excel XML shows — Please Select a Category — string instead.
What should I do? Modify parent ConvertToXml? Point me in the right direction, please.