2

How can i create button on Product listing page in admin menu.

enter image description here

2 Answers 2

0

The product form is generated via ui-components. The ui component name for product form is view/adminhtml/ui_component/product_form.xml.

You need to create a file with the same name and path in your own module 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.php in this file write below code

<?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' => __('Your button label here'),
            'on_click' => "alert('it works')",
            'sort_order' => 100
        ];
    }
}

Your Button will display in your product form.

2
  • Not working for Magento 2.2 Commented Nov 19, 2018 at 21:29
  • I want to open a form by clicking on this button is it possible??
    – Ghulam.M
    Commented Mar 14, 2019 at 16:18
0

you can follow following links to create the custom button...

Magento 2. Add custom button on product grid using the layout handle

or you can create one file under [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">
    <settings>
        <buttons>
            <button name="priority_import_products_all">
                <url path="priority/sync/products"/>
                <label translate="true">Custom Button Name</label>
                <class>action-secondary</class>
            </button>
        </buttons>
    </settings>
</listing>

enter image description here

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.