0

I have a product block like(refer image) and I loaded the productgrid using( https://www.rohanhapani.com/magento-2-how-to-add-product-grid-in-ui-form-using-uicomponent/)and successfully saved.After when I try to edit the block (I Want to add more products to grid) I have only seen the products that I added early only. How to add new products to the grid?

enter image description here

1 Answer 1

0

For adding the button through UI form, you need to do following steps

view/adminhtml/ui_component/custom_created_form.xml

You need to add data with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="buttons" xsi:type="array">
            <item name="button-unique-identifier-here" xsi:type="string">[Namespace]\[Module]\Block\Adminhtml\Product\Edit\Button\CustomButton</item>
        </item>
    </argument>
</form>

Then create the class

[Namespace][Module]\Block\Adminhtml\Product\Edit\Button\CustomButton in the file [Namespace]/[Module]/Block/Adminhtml/Product/Edit/Button/CustomButton.php

<?php 
namespace [Namespace]\[Module]\Block\Adminhtml\Product\Edit\Button;

use Magento\Catalog\Block\Adminhtml\Product\Edit\Button\Generic;

class CustomButton extends Generic
{
    public function getButtonData()
    {
        return [
            'label' => __('Add Product'),
            'on_click' => "alert('it works..')",
            'class' => 'primary',
            'sort_order' => 100
        ];
    }
}

Please upvote the answer if helpful

1
  • Actually I have loaded the productgrid using( rohanhapani.com/… )and successfully saved.After when I try to edit the block (I Want to add more products to grid) I have only seen the products that I added early only. How to add new products to the grid?????
    – Alshihab
    Sep 21, 2022 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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