Magento Customer Grid Customisation is very handy.
Follow the steps to customize the Customer Grid in Magento 2 and add the Customer's last logged-in date.
Magento Customer Grid Customisation is very handy.
Follow the steps to customize the Customer Grid in Magento 2 and add the Customer's last logged-in date.
app/code/Elightwalk/CustomerGrid/registration.php 1
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Elightwalk_CustomerGrid',
__DIR__
);
app/code/Elightwalk/CustomerGrid/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Elightwalk_CustomerGrid" setup_version="1.0.0">
<sequence>
<module name="Magento_Customer"/>
</sequence>
</module>
</config>
app/code/Elightwalk/CustomerGrid/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" class="Magento\Customer\Ui\Component\Listing\Columns" >
<column name="last_login" class="Elightwalk\CustomerGrid\Ui\Component\Listing\Column\LastLogin" component="Magento_Ui/js/grid/columns/date" sortOrder="90">
<settings>
<dataType>date</dataType>
<label translate="true">Customer Last Login</label>
<sortable>false</sortable>
<filter>false</filter>
</settings>
</column>
</columns>
</listing>
app/code/Elightwalk/CustomerGrid/Ui/Component/Listing/Column/LastLogin.php
<?php
namespace Elightwalk\CustomerGrid\Ui\Component\Listing\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
class LastLogin extends Column
{
protected $logger;
/**
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
array $components = [],
array $data = [],
\Magento\Customer\Model\Logger $logger
) {
$this->logger = $logger;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$item[$this->getData('name')] = $this->logger->get($item['entity_id'])->getLastLoginAt();//Value which you want to display
}
}
return $dataSource;
}
}
Inside your terminal or CMD
php bin/magento module:enable Elightwalk_CustomerGrid
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean
Contact us:+91 8128405131
Email send us at hello@elightwalk.com
Table of contents
Jayram Prajapati brings expertise and innovation to every project he takes on. His collaborative communication style, coupled with a receptiveness to new ideas, consistently leads to successful project outcomes.
With a single command, you can improve the security of your website! Explore our step-by-step guide to password options and creating a robust and unique authentication method for online platform.
When retrieving orders using the Magento REST API, troubleshoot the 'Duplicate Entry' problem. Our guide gives insights and solutions to ensure a seamless and error-free order retrieval experience on Magento platform.
Improve your client management with Magento 2! Learn how to add the order value to customer grid column step by step. Improve visibility and consumer insights for informed and efficient shopping experience.