1

I want to remove .000 after quantity in admin grid is there any way to remove decimal from quantity column. enter image description here

1 Answer 1

2

Follow the below steps for remove decimal from qty :

You need to add sequence in your module.xml file

<module name="Vendor_Module" setup_version="1.0.0">
    <sequence>
        <module name="Magento_CatalogInventory"/>
    </sequence>
</module>

Create product_listing.xml file at

app/code/Vendor/Module/view/adminhtml/ui_component/product_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="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
        <column name="qty" class="Vendor\Module\Ui\Component\Listing\Columns\QtyFile">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="add_field" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">Quantity</item>
                    <item name="sortOrder" xsi:type="number">75</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Add Renderer file QtyFile.php at

app/code/Vendor/Module/Ui/Component/Listing/Columns/QtyFile.php

<?php

namespace Vendor\Module\Ui\Component\Listing\Columns;

class QtyFile extends \Magento\Ui\Component\Listing\Columns\Column
{
    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            $fieldName = $this->getData('name');
            foreach ($dataSource['data']['items'] as & $item) {
                if (isset($item[$fieldName])) {
                    $item[$fieldName] = (int)$item[$fieldName];
                }
            }
        }

        return $dataSource;
    }
}

Then, Upgrade your module and clean cache.

Reference

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.