1

I used below code to display the delivery date now i want to call my custom file to filter the admin side grid section in sales order grid section.

<?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="sales_order_columns">
        <column name="delivery_date" class="Magento\Ui\Component\Listing\Columns\Date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                    <item name="dataType" xsi:type="string">date</item>
                    <item name="label" xsi:type="string" translate="true">Delivery Date</item>
                    <item name="dateFormat" xsi:type="string">MMM dd, YYYY</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>
2

Put this

<column name="created_at" class="vendore\ModuleName\Ui\Component\Listing\Column\DateChangeActions">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="editor" xsi:type="string">text</item>
            <item name="filter" xsi:type="string">dateRange</item>
            <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
            <item name="dataType" xsi:type="string">date</item>
            <item name="label" xsi:type="string" translate="true">new date</item>
            <item name="dateFormat" xsi:type="string">MMM dd, YYYY</item>
        </item>
    </argument>
</column>

and this your change file

<?php

namespace vendore\ModuleName\Ui\Component\Listing\Column;

use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Ui\Component\Listing\Columns\Column;

class DateChangeActions extends Column
{
    protected $urlBuilder;

    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        UrlInterface $urlBuilder,
        array $components = [],
        array $data = []
    ) {
        $this->urlBuilder = $urlBuilder;
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as &$item) {
                if (isset($item['created_at'])) {
                        // your Code what you want
                }
            }
        }
        return $dataSource;
    }
}
|improve this answer|||||
  • Can you explain how/why this works please? – Ben Crook Jan 29 at 15:55
  • @BenCrook the filter is dependent on which type of Data you store in database and show in your grid. But you used different filter to different data so it's not work. Because data not found . – Msquare Jan 30 at 3:16
  • @BenCrook and you need to custom filter you have to override this class Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool and Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider – Msquare Jan 30 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.