I need to change the position of custom mass action dropdown option in sales order grid
Please check screenshot:
Just need to show the Sync option to on top position before delete.
Does anyone have idea for the same?
Thanks in advance
Try adding this
<item name="sortOrder" xsi:type="number">2</item>
Thanks
This can be done using a plugin:
adminhtml/di.xml:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Ui\Component\MassAction">
<plugin name="CustomVendor_CustomActions::sort_actions" type="CustomVendor\CustomActions\Plugin\Component\MassAction" sortOrder="100"/>
</type>
</config>
Plugin\Component\MassAction.php:
<?php
namespace CustomVendor\CustomAction\Plugin\Component;
use Magento\Framework\App\RequestInterface;
class MassAction
{
/** @var RequestInterface */
private $_request;
/**
* MassAction constructor.
* @param RequestInterface $request
*/
public function __construct(
RequestInterface $request
)
{
$this->_request = $request;
}
/**
* @param ComponentMassAction $massAction
*/
public function afterPrepare(ComponentMassAction $massAction)
{
if ($this->_request->getFullActionName() === 'sales_order_index') {
$config = $massAction->getData('config');
if (isset($config['actions']) && $config['actions']) {
$count = 0;
foreach (["custom_action_1" => 0, "custom_action_2" => 1] as $actionType => $position) {
/** @var $config mixed[][] */
foreach ($config['actions'] as $key => $action) {
if ($action['type'] == $actionType) {
$newPosition = max((int) $position, $count);
$this->moveElement($config['actions'], $key, $newPosition);
break;
}
}
$count++;
}
$massAction->setData('config', $config);
}
}
}
/**
* @param array $actions
* @param int $oldPosition
* @param int $newPosition
*/
public function moveElement(&$actions, $oldPosition, $newPosition)
{
$outputArray = array_splice($actions, $oldPosition, 1);
array_splice($actions, $newPosition, 0, $outputArray);
}
}
I had no luck using module sequence or sortOrder param in XML to achieve this. Plugin is the only method that worked for me in Magento 2.4.3.