0

I need to change the position of custom mass action dropdown option in sales order grid

Please check screenshot:

enter image description here

Just need to show the Sync option to on top position before delete.

Does anyone have idea for the same?

Thanks in advance

2 Answers 2

0

Try adding this

<item name="sortOrder" xsi:type="number">2</item>

Thanks

3
  • This is working for a sales order grid. But how I can show the same option on top in customer listing dropdown mass action?
    – Shomita
    Commented Aug 12, 2020 at 7:28
  • please reply for above question
    – Shomita
    Commented Aug 12, 2020 at 7:41
  • I thought both are same as both are mass Action Dropdown can you share a few more detail ScreenShot - Thanks Commented Aug 14, 2020 at 9:42
0

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.

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.