You need to apply your custom class(Namespace\Modulename\Ui\Component\Listing\Columns\Date)
instead of default magento class (Magento\Ui\Component\Listing\Columns\Date)
.
Now create above given class file located at :
Namespace\Modulename\Ui\Component\Listing\Columns\Date
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Namespace\Modulename\Ui\Component\Listing\Columns;
use Magento\Framework\Stdlib\BooleanUtils;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
/**
* @api
* @since 100.0.2
*/
class Date extends \Magento\Ui\Component\Listing\Columns\Date
{
/**
* @inheritdoc
*/
public function prepareDataSource(array $dataSource)
{
//Du stuff your logic
}
}
UPDATE :
Suppose you need to add filters to your collection and you want to display your grid using ui_component as they allow you to configure the page manipulating the UI components, then follow the steps below.
Now suppose you want to display products whose price is greater than 100.
Add this code in your
Namespace/ModuleName/view/adminhtml/ui_component/example.xml
<dataSource name="test_products_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Namespace\ModuleName\Ui\DataProvider\Product\ProductDataProvider</argument>
<argument name="name" xsi:type="string">test_products_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">entity_id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="update_url" xsi:type="url" path="mui/index/render"/>
</item>
</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
</item>
</argument>
</dataSource>
n the code above,
<argument name=”class” xsi:type=”string”>Namespace\ModuleName\Ui\DataProvider\Product\ProductDataProvider</argument>
Now in file ProductDataProvider.php in
Namespace/ModuleName/Ui/DataProvider/Product
namespace Namespace\ModuleName\Ui\DataProvider\Product;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
class ProductDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
{
public function __construct(
CollectionFactory $collectionFactory,
$name,
$primaryFieldName,
$requestFieldName,
array $meta = [],
array $data = []
) {
$collection = $collectionFactory->create();
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$meta,
$data
);
$this->collection = $collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('price', ['gt' => 100]);
}
}
Note : Above code is not tested. You need to add logic as per your requirement.
I hope it helps!