How to Add Dynamic Mass Action in Admin Grid in Magento 2

The Mass Actions component allows performing specific actions with multiple selected items. Admin can perform a mass operation on the selected items quickly. It saves the admin from the tedious process of completing an operation on a one-by-one record. 

Having a grid in Magento 2 means loads of records maintained in that admin grid, and need often arrives to perform mass action on the various records. No individual or separate record operation is required if the admin grid has a mass action facility.

Magento 2 comes with a UI component that assists store admins in adding more items such as columns, filter argument, paging, mass action, etc., for the admin grid.

Earlier, I did post a solution to add custom mass action in order grid in Magento 2.

However, sometimes you may have to dynamically add mass action in the admin grid according to your requirements.

For instance, the admin grid has a column named ‘status’ with three records- pending, confirmed, and unconfirmed. Now admin wants to change all the unconfirmed status with confirmed one and pending status with confirmed. Also, if a new status “cancelled” is created, the cancel status must be available as an option dynamically while using this custom mass action.

Or, if you are using the custom mass action to upgrade the customer group of your selected customers from the grid and you create a custom customer group, using the below solution to add dynamic mass action in admin grid in Magento 2, your custom group will be available as an option dynamically! 

Method to Add Dynamic Mass Action in Admin Grid in Magento 2

  1. Use the below code in the data_listing.xml at Vendor/Extension/view/adminhtml/ui_component

  2. Use the below code in the di.xml file at Vendor/Extension/etc

  3. Paste the below code in the Options.php file at Vendor/Extension/UI/Component/MassAction/Status

  4. Use the below code in MassChangeStatus.php file at Vendor/Extension/Controller/Adminhtml/Index

After applying the above method, the mass action displays in the admin grid as shown below:

How to Add Dynamic Mass Action in Admin Grid in Magento 2

Quite lengthy but worth applying. Right?

If you have queries regarding this blog, feel free to ask in the Comments section below.

I would be happy to answer your question.

Do consider sharing this post with Magento Community via social media.

Thank you.

(based on 12 Reviews)
How to Add Dynamic Mass Action in Admin Grid in Magento 2Author Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply

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