I want to add/filter country_id column of shipping address in sales order grid.

I refer below link which is useful to display regoin_id.

By doing same I am able to add country id as a column but when I perform filter on that ambiguous error is generated.


enter image description here

Please check below code, I changed for country id :

public function afterGetReport($subject, $collection, $requestName)
    if ($requestName !== 'sales_order_grid_data_source') {
        return $collection;

    if ($collection->getMainTable() === $collection->getResource()->getTable('sales_order_grid')) {
        try {
             $orderAddressTableName           = $collection->getResource()->getTable('sales_order_address');
            $directoryCountryRegionTableName = $collection->getResource()->getTable('directory_country_region');
                ['soat' => $orderAddressTableName],
                'soat.parent_id = main_table.entity_id AND soat.address_type = \'shipping\'',
                ['dcrt' => $directoryCountryRegionTableName],
                'soat.region_id = dcrt.region_id',
                ['dcrt' => $directoryCountryRegionTableName],
                'soat.country_id = dcrt.country_id',
        } catch (\Zend_Db_Select_Exception $selectException) {
            // Do nothing in that case
            $this->logger->log(100, $selectException);

    return $collection;


   <column name="country_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
                <item name="label" xsi:type="string" translate="true">Country Id</item>
                <item name="sortOrder" xsi:type="number">65</item>
                <item name="align" xsi:type="string">left</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="filter" xsi:type="string">text</item>
  • Did you get any further with this?
    – elfling
    Jan 14, 2021 at 17:27

1 Answer 1


If it is no collection


return $collection;


return $result

Full working code for country_id would be as follows

use Magento\Framework\Message\ManagerInterface as MessageManager;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as SalesOrderGridCollection;

class AddColumnsSalesOrderGridCollection
    private $messageManager;
    private $collection;

    public function __construct(MessageManager $messageManager,
                                SalesOrderGridCollection $collection
    ) {

        $this->messageManager = $messageManager;
        $this->collection = $collection;

    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();

                    ["soa" => "sales_order_address"],
                    'main_table.entity_id = soa.parent_id AND soa.address_type="shipping"',
                return $this->collection;

        return $result;


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.