---
title: "Add Tree Mass action Dynamically In Sales Order Grid in Magento 2"
url: "https://magecomp.com/blog/add-tree-mass-action-dynamically-in-sales-order-grid-in-magento-2/"
date: "2018-03-12T18:37:22+00:00"
modified: "2025-02-21T12:53:24+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 919
reading_time: "5 min read"
summary: "Being Rich E-commerce CMS, Magento does take care of each and every need of the store owner to make their day to day store management much easier than you think. Among all available features, Magen..."
description: "Create and your own dynamic tree mass action in your Magento 2 admin sales order grid for providing more convenience to store owner and saving tons of time a..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Add Sample CSV Download Option in System Configuration"
    url: "https://magecomp.com/blog/magento-2-add-sample-csv-download-option-in-system-configuration/"
  - title: "How to Apply Custom CSS for Specific CMS Page using a CSS file in Magento 2?"
    url: "https://magecomp.com/blog/apply-custom-css-for-specific-cms-page-magento-2/"
  - title: "How to Set and Get Cookie in Magento 2?"
    url: "https://magecomp.com/blog/set-and-get-cookie-magento-2/"
---

# Add Tree Mass action Dynamically In Sales Order Grid in Magento 2

_Published: March 12, 2018_  
_Author: Dhiren Vasoya_  

![Add Tree Mass action Dynamically In Sales Order Grid in Magento 2](https://magecomp.com/blog/wp-content/uploads/2018/03/Add-Tree-Mass-action-Dynamically-In-Sales-Order-Grid-in-Magento-2-1024x332.webp)

Being Rich E-commerce CMS, Magento does take care of each and every need of the store owner to make their day to day store management much easier than you think. Among all available features, Magento offers Mass action that is very helpful to store owner for easy management of orders and customers by carrying out the same action on multiple records. Mass action on the grid can help saving tones of time for the store owner and let them utilize that saved time towards their business success.

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)
Working with Magento custom development, we always tried to provide such feature pack solutions to our customer that meets their business needs & can be helpful in saving tons of time and efforts of store owners. Recently while working on the project, one of our clients requested to implement tree mass action functionality in their sales order grid of store backend for their convenience & easy maintenance of products by applying the same action on multiple selections. After spending an hour, we are really happy by delivering a smile.
Today at MageComp blog, I would likely to share that code with you guys, that can help you to save tones of time by Adding Tree Mass action Dynamically in Sales Order Grid of Magento 2. Simply follow these steps and you are ready to display your own actions in sales grid.

Firstly, you need to add your own mass actions to Sales order actions list by adding following code to ‘sales_order_grid.xml’ available on below path.
**app\code\Vendor\Extension\view\adminhtml\ui_component\sales_order_grid.xml**

```

<?xml version="1.0" encoding="UTF-8"?>
        	         	<massaction name="listing_massaction">
                    	 <argument name="data" xsi:type="array">
                                	 <item name="config" xsi:type="array">
                                            	 <item name="selectProvider" xsi:type="string">sales_order_grid.sales_order_grid.sales_order_columns.ids</item>
                                            	 <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
                                            	 <item name="indexField" xsi:type="string">entity_id</item>
                                	 </item>
                    	 </argument>
                    	 <action name="select_extension">
                                	 <argument name="data" xsi:type="array">
                                            	 <item name="config" xsi:type="array">
                                                        	 <item name="type" xsi:type="string">extension_id</item>
                                                        	 <item name="label" xsi:type="string" translate="true">Order Status</item>
                                            	 </item>
                                	 </argument>
                                	 <argument name="actions" xsi:type="configurableObject">
                                            	 <argument name="class" xsi:type="string">VendorExtensionUiComponentMassaction</argument>
                                            	 <argument name="data" xsi:type="array">
                                                        	 <item name="urlPath" xsi:type="string">extension/extension/massstatus/</item>
                                                        	 <item name="paramName" xsi:type="string">extension_id</item>
                    	                                	 <item name="confirm" xsi:type="array">
                                                                    	 <item name="title" xsi:type="string" translate="true">Order Status</item>
                                                                    	 <item name="message" xsi:type="string" translate="true">Are you sure to change order status?</item>
                                                        	 </item>
                                                 </argument>
                                	 </argument>
                    	 </action>
        	 </massaction>
        	```

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-3.webp)](https://magecomp.com/services/hire-magento-programmer/)

Once the mass actions is listed, now you need to specify the code that performed on click of that action. To add your custom action, you need to create ‘Massaction.php’ file at below path along with custom action code.
**app\code\Vendor\Extension\Ui\Component\Massaction.php**

```

<?php
namespace VendorExtensionUiComponent;

use MagentoFrameworkUrlInterface;
use ZendStdlibJsonSerializable;
use VendorExtensionModelResourceModelExtensionCollectionFactory;

class Massaction implements JsonSerializable
{
        	protected $options;
        	protected $collectionFactory;
        	protected $data;
        	protected $urlBuilder;
        	protected $urlPath;
        	protected $paramName;
        	protected $additionalData = [];

        	public function __construct(
         	CollectionFactory $collectionFactory,
         	UrlInterface $urlBuilder,
         	array $data = []
        	) {
         	$this->collectionFactory = $collectionFactory;
         	$this->data = $data;
         	$this->urlBuilder = $urlBuilder;
        	}

        	/**
        	* Get action options
        	*
        	* @return array
        	*/
        	public function jsonSerialize()
        	{
         	$i=0;
         	if ($this->options === null) {
         	// get the massaction data from the database table
         	$badgeColl = $this->collectionFactory->create();

         	if(!count($badgeColl)){
             return $this->options;
         	}
         	//make a array of massaction
         	foreach ($badgeColl as $key => $badge) {
             $options[$i]['value']=$badge->getExtensionId();
             $options[$i]['label']=$badge->getExtensionStatus();
             $i++;
         	}
         	$this->prepareData();
         	foreach ($options as $optionCode) {
             $this->options[$optionCode['value']] = [
                      	'type' => 'extension_' . $optionCode['value'],
                      	'label' => $optionCode['label'],
             ];

             if ($this->urlPath && $this->paramName) {
                      	$this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl(
                      	$this->urlPath,
                      	[$this->paramName => $optionCode['value']]
                      	);
             }

             $this->options[$optionCode['value']] = array_merge_recursive(
                      	$this->options[$optionCode['value']],
                      	$this->additionalData
             );
         	}

         	// return the massaction data
                    	$this->options = array_values($this->options);
         	}
         	return $this->options;
        	}

        	/**
        	* Prepare addition data for subactions
        	*
        	* @return void
        	*/
        	protected function prepareData()
        	{

         	foreach ($this->data as $key => $value) {
         	switch ($key) {
             case 'urlPath':
                      	$this->urlPath = $value;
                      	break;
             case 'paramName':
                      	$this->paramName = $value;
                      	break;
             default:
                      	$this->additionalData[$key] = $value;
                      	break;
         	}
         	}
        	}
}
```

You can even add more event actions to ‘Massactions.php’ file as per your need by customizing this code.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)
Feel free to share this code and ask your questions in the comments below if you are looking for any help regarding this code as per your need.
Happy Coding!


---

_View the original post at: [https://magecomp.com/blog/add-tree-mass-action-dynamically-in-sales-order-grid-in-magento-2/](https://magecomp.com/blog/add-tree-mass-action-dynamically-in-sales-order-grid-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-25 18:57:28 UTC_  
