1

I'm using magento 2.3.5 below is my code Custmergrid/view/adminhtml/ui_component/customer_listing.xml

<?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="customer_columns">
        <column name="my_column" class="Shruti\Custmergrid\Ui\Component\Listing\Column\Mycolumn">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" translate="true" xsi:type="string">My column</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Custmergrid/Ui/Component/Listing/Column/Mycolumn.php

<?php
namespace Shruti\Custmergrid\Ui\Component\Listing\Column;
 
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;
 
class Mycolumn extends \Magento\Ui\Component\Listing\Columns\Column
{
    protected $_customerRepository;
    protected $_searchCriteria;

    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        CustomerRepositoryInterface $customerRepository,
        SearchCriteriaBuilder $criteria,
        array $components = [],
        array $data = []
    ) {
        $this->_customerRepository = $customerRepository;
        $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) {
                $customer  = $this->_customerRepository->getById($item["entity_id"]);
 
                $customer_id = $customer->getId();               
                $item[$this->getData('name')] = 'Here';
            }
        }
        return $dataSource;
    }
}
6
  • can you tell what issue you are facing. as i tried your code and it's working. Jul 3, 2020 at 10:20
  • @AfreenSheikh Not showing in the grid
    – Kanika
    Jul 3, 2020 at 10:33
  • @AfreenSheikh what is your magento version?
    – Kanika
    Jul 3, 2020 at 10:35
  • 2.3.4-p2 magento I'm using Jul 3, 2020 at 10:37
  • I tried in 2.3.5 also. it's working fine. it can be a cache issue. try by flushing cache once Jul 3, 2020 at 10:59

0

Your Answer

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

Browse other questions tagged or ask your own question.