0

How to create a grid under custom tab in product View/Edit Page in Magento2?(like Product Review grid)

If anyone knows Please explain me ..

Thanks.

0

First of all create a basic module and check the module is working

Then create ‘catalog_product_edit.xml’ file in location Vendor/Demo/view/adminhtml/layout.

 <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product_form">
            <block class="Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo" name="demo.tab">
                <arguments>
                    <argument name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Demo Tab</item>
                        <item name="collapsible" xsi:type="boolean">true</item>
                        <item name="opened" xsi:type="boolean">true</item>
                        <item name="sortOrder" xsi:type="string">2</item>
                        <item name="canShow" xsi:type="boolean">true</item>
                        <item name="componentType" xsi:type="string">fieldset</item>
                    </argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

Now create block ‘Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo’. Create Demo.php in location Vendor/Demo/Block/Adminhtml/Catalog/Product/Edit/Tab.

    <?php
namespace Vendor\Demo\Block\Adminhtml\Catalog\Product\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

class Demo extends \Magento\Framework\View\Element\Template
{
    /**
     * @var string
     */
    protected $_template = 'product/edit/demo.phtml';

    /**
     * Core registry
     *
     * @var Registry
     */
    protected $_coreRegistry = null;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    )
    {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Retrieve product
     *
     * @return \Magento\Catalog\Model\Product
     */
    public function getProduct()
    {
        return $this->_coreRegistry->registry('current_product');
    }

}

Finally create template file demo.phtml in location Vendor/Demo/view/adminhtml/templates/product/edit.

In this template you can write your custom code

eg: screenshot added enter image description here

|improve this answer|||||

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.