Create sales_order_grid.xml
inside adminhtml > ui_component
directory
<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="business_name" class="Vendor\Module\Ui\Component\Listing\Column\BusinessName">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="bodyTmpl" xsi:type="string">text</item>
<item name="label" translate="true" xsi:type="string">Attribute Title</item>
<item name="sortable" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">25</item>
</item>
</argument>
</column>
</columns>
</listing>
Then create a class inside Vendor\Module\Ui\Component\Listing\Column\BusinessName.php
<?php
namespace Vendor\Module\Ui\Component\Listing\Column;
use Magento\Customer\Model\CustomerFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Asset\Repository;
class BusinessName extends Column
{
/**
* @var Magento\Customer\Model\CustomerFactory $block
*/
protected $customerFactory;
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepository;
/**
* @var Magento\Framework\UrlInterface
*/
private $urlBuilder;
/**
* @param Repository $assetRepository
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param CustomerFactory $customerFactory
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
Repository $assetRepository,
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
CustomerFactory $customerFactory,
UrlInterface $urlBuilder,
array $components = [], array $data = [])
{
$this->assetRepository = $assetRepository;
$this->customerFactory = $customerFactory;
$this->urlBuilder = $urlBuilder;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$customer = $this->customerFactory->create()->load($item["entity_id"]);
$businessName = $customer->getBusinessName();
if($businessName != ''){
$item[$this->getData('name')] = $businessName;
}
}
}
return $dataSource;
}
}
Let me know if have any query.