1

I want to add the date on which a product was created to the default product admin grid.

I've created a module under app\code\Vendor\Module with:

./etc/module.xml

<?xml version="1.0" encoding="utf-8" ?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>

./composer.json

{
  "name": "vendor/module-module",
  "description": "",
  "type": "magento2-module",
  "license": "proprietary",
  "authors": [
    {
      "email": "info@mage2gen.com",
      "name": "Mage2Gen"
    }
  ],
  "minimum-stability": "dev",
  "require": {},
  "autoload": {
    "psr-4": {
      "Vendor\\Module\\": ""
    },
    "files": [
      "registration.php"
    ]
  }
}

./registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);

following this I ran bin/magento setup:upgrade and have the expected result of the app/etc/config.php file being updated with my module.

From what I understand I now only need to add some xml to a file similar to what Magento core is using and refresh the cache to see some results. This should be app/code/Vendor/Module/view/adminhtml/ui_component/product_listing.xml. I found the following: Add Custom Product Grid Created Date And Created By Magento 2

which suggests that if I add the following 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="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
        <column name="created_at" component="Magento_Ui/js/grid/columns/date">
             <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="label" xsi:type="string" translate="true">Created Date</item>
                    <item name="sortOrder" xsi:type="number">71</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

I should see the desired results. Other reading suggests that even if it's not showing me the desired results I should at least see an empty column name or something of the like in the grid, but that's not happening.

I also tried using this:

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
    <column name="custom_field">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="add_field" xsi:type="boolean">true</item>
                <item name="label" xsi:type="string" translate="true">Custom Field</item>
                <item name="sortOrder" xsi:type="number">75</item>
            </item>
        </argument>
    </column>
</columns>
</listing>

As well as updating the snippet using another module that I know works so that it would look like:

<listing>
    <columns name="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <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">Created Date</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Still not seeing anything occur in the grid at all. The grid I'm l;ooking at is Products / Inventory / Catalog. Any ideas on what's going on would be appreciated.

  • please attach screen shot – Rk Rathod Jan 9 at 12:41
  • it was a typo... the file name was product_lsiting.xml – Caius Jan 9 at 13:10

Your Answer

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

Browse other questions tagged or ask your own question.