Back to Top

Adding Custom Mass Action In Admin Grid In Magento 2

In this post we will see how to add custom mass action in grid. Following this post we can add Mass Action to any grid.

Customers Grid in Magento 2 is made by using ui_component. We will extend the customer  ui_component file customer_listing.xml file in our module to add custom mass action.

Create file customer_listing.xml in /app/code/your_namespace/your_moduleName/view/adminhtml/ui_component/

In this file create mass action as below:

<?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">
    <listingToolbar name="listing_top">
        <massaction name="listing_massaction">
            <action name="sendconfirmation">
                <settings>
                    <confirm>
                        <message translate="true">Are you sure to send Confirmation Mail to selected customers?</message>
                        <title translate="true">Send Mail</title>
                    </confirm>
                    <url path="modulename/index/massSendConfirmation"/> <!-- your custom controller to handle request -->
                    <type>sendconfirmation</type>
                    <label translate="true">Send Confirmation</label>
                </settings>
            </action>
        </massaction>
    </listingToolbar>
</listing>

Now, when you will see the Customer Grid then you can find Custom Action has been added to drop down.

customer grid mass action image

That’s it for this post. Thanks 🙂

. . .

Leave a Comment

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


2 comments

  • Andresa
    • Ayaz Mittaqi (Moderator)
  • Back to Top

    Message Sent!

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

    Back to Home