I have created a custom column updated_at on customer grid. I have displayed it with data. But when I click the column header, this error pops out (Something went wrong with processing the default view and we have restored the filter to its original state.)
I added customer_listing on adminhtml/ui_components.
This is the code inside my 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="updated_at" class="Mvn\Cam\Ui\Component\Listing\Column\CustomerList">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="dataType" xsi:type="string">date</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dateFormat" xsi:type="string" translate="true">MMM d, Y hh:mm a</item>
<item name="label" translate="true" xsi:type="string">Updated At</item>
<item name="sortOrder" xsi:type="number">1</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
<item name="sortable" xsi:type="boolean">true</item>
</item>
</argument>
</column>
</columns>
</listing>
Here is my code at Ui\Component\Listing\Column
<?php
namespace Mvn\Cam\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\Api\SearchCriteriaBuilder;
class CustomerList extends Column
{
protected $customerFactory;
protected $_searchCriteria;
protected $helperReferralCode;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
\Magento\Customer\Model\CustomerFactory $customerFactory,
SearchCriteriaBuilder $criteria, //my custom module from which i want to add new column
array $components = [], array $data = [])
{
$this->customerFactory = $customerFactory;
$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) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$updatedat = $objectManager->create('Magento\Customer\Model\Customer')->load($item['entity_id']);
$item[$this->getData('name')] = $updatedat->getUpdatedAt();
}
}
return $dataSource;
}
}
Here is the Screenshot of the page