Back to Top

Add stock management column in product grid Magento 2

Updated 18 April 2024

Here, we will see how to add stock management column in product grid Magento 2.

It’s easy to add a column to the products grid if a value that you want to display in the column is a product attribute. They are already present in the products grid toolbar under Columns control.

You just check/uncheck columns that you want to display or remove from the grid. But what if you want to display values like quantity and website that aren’t product attribute?

Because stock management can be turned on/off per product, we will add a new column to the products grid that will display if stock management is turned on or off.

Steps to add stock management column in product grid Magento 2

For all of the code examples, I created a Magento 2 module, named Webkul_Custom.

Searching for an experienced
Magento 2 Company ?
Find out More

If you want to learn how to create a Magento 2 module, you can check this: How to create a basic module in Magento 2

It’s important that Magento’s Magento_Catalog module is loaded before our module, that’s why we will add it under sequence tag in the module.xml file.


<?xml version="1.0"?>

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Webkul_Custom" >
            <module name="Magento_Catalog"/>

To render products grid Magento 2 uses Listing UI component instance named product_listing and XML configuration file for it. We need to create a file in our module with the same path and name.


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

<listing xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="product_columns">
        <column name="manage_stock" component="Magento_Ui/js/grid/columns/select" sortOrder="80">
                <label translate="true">Manage Stock</label>
                <options class="Magento\Config\Model\Config\Source\Yesno"/>

To add new column we need to reference columns UI component named product_columns from the original config file and add our new column to it. We named our column manage_stock with label Manage Stock.

First, we will create a field strategy that will add stock management status to the products collection.



namespace Webkul\Custom\Ui\DataProvider\Product;

class AddManageStockFieldToCollection implements \Magento\Ui\DataProvider\AddFieldToCollectionInterface
    public function addField(
        \Magento\Framework\Data\Collection $collection,
        $alias = null
    ) {

For times when someone wants to filter grid data by stock management status, we need to create this filtering strategy.


namespace Webkul\Custom\Ui\DataProvider\Product;

class AddManageStockFilterToCollection implements \Magento\Ui\DataProvider\AddFilterToCollectionInterface
    public function addFilter(
        \Magento\Framework\Data\Collection $collection,
        $condition = null
    ) {
        if (isset($condition['eq'])) {
            $collection->addFieldToFilter($field, $condition);

If we want to use just created strategies we need to add them to the product_listing data provider. We will do that in the di.xml file.


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

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> 
    <type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
            <argument name="addFieldStrategies" xsi:type="array">
                <item name="manage_stock" xsi:type="object">Webkul\Custom\Ui\DataProvider\Product\AddManageStockFieldToCollection</item>
            <argument name="addFilterStrategies" xsi:type="array">
                <item name="manage_stock" xsi:type="object">Webkul\Custom\Ui\DataProvider\Product\AddManageStockFilterToCollection</item>

After that, install the module properly and see the results as showing in below screenshot.

stock management column in product grid

Thank you for reading this article on How to add stock management column in product grid Magento 2, we hope you liked it.
You can also view our wide range of ready-to-use Magento 2 extensions.

Other Blogs:

  1. Magento 2 Development 05: Layout and Templates
  2. How to create custom layout page in magento2

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home