1

In Magento 1 one could add a custom button on the product grid using the layout handle.

One would add the following to local.xml

<layout version="0.1.0">
    <!-- ... -->
    <adminhtml_catalog_product_index>
        <reference name="products_list">
            <action method="addButton">
                <id>my_button_identifier</id>
                <data>
                    <label>My button</label>
                    <class>some-class</class>
                    <onclick>some_click_action_here</onclick>
                </data>
            </action>
        </reference>
    </adminhtml_catalog_product_index>
    <!-- ... -->
</layout>
  • Is this possible in Magento 2? If so how?

I've tried with no luck:

Vendor/Module/view/adminhtml/layout/catalog_product_index.xml

<?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="products_list">
            <action method="addButton">
                <argument name="buttonId" xsi:type="string">button_id</argument>
                <argument name="data" xsi:type="array">
                    <item name="label" xsi:type="string">Button Label</item>
                    <item name="class" xsi:type="string">primary</item>
                    <item name="url" xsi:type="string">frontname/controller/controller</item>
                    <item name="class_name" xsi:type="string">Magento\Backend\Block\Widget\Button</item> <!-- Tried without this node as well -->
                </argument>
            </action>
        </referenceBlock>
    </body>
</page>

EDIT

I can confirm that the addButton Method is called for my input, yet the button still is not displayed in frontend

2
  • Can You Please Provide Some More Information> @vitoriodachef Commented Jun 13, 2018 at 15:41
  • More information regarding what? Commented Jun 14, 2018 at 9:03

1 Answer 1

1

On Magento 2, you can add custom button in product listing by this creating file: app/code/Vendor/ModuleName/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">Your button title</label>
                <class>action-secondary</class>
            </button>
        </buttons>
    </settings>
</listing>

Result: 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.