I am trying to create a custom drop down option in Action section in the sales order Grid.
The main gold is to bring custom Option(Assign to User) in Action Drop down.
Then once Assign to user is clicked it should list all available users in next drop down. so if any user is selected then the selected order should assign to that particular user.
I have used this code so far. but I am not getting my custom option in the Action drop down.
<?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>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="assigned_user_id" class="Vendor\Module\Ui\Component\Listing\MassActions\DynamicAction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">assigned_user_id</item>
<item name="label" xsi:type="string" translate="true">Bulk Assign</item>
<item name="assigned_user_id" xsi:type="object">Vendor\Module\Ui\DataProvider\UserActions</item>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
Vendor\Module\Ui\Component\Listing\MassActions\DynamicAction.php
<?php
namespace Vendor\Module\Ui\Component\Listing\MassActions;
class DynamicAction extends \Magento\Ui\Component\Action
{
/**
* @inheritDoc
*/
public function prepare()
{
$config = $this->getData('config');
if(isset($config['assigned_user_id'])) {
$this->actions = $config['assigned_user_id']->getActions();
}
parent::prepare();
}
}
Vendor\Module\Ui\DataProvider\UserActions.php
<?php
namespace Vendor\Module\Ui\DataProvider;
use Magento\User\Model\ResourceModel\User\CollectionFactory;
use Magento\Framework\UrlInterface;
class UserActions
{
protected $collectionFactory;
protected $urlBuilder;
public function __construct(CollectionFactory $collectionFactory,
UrlInterface $urlBuilder)
{
$this->collectionFactory = $collectionFactory;
$this->urlBuilder = $urlBuilder;
}
public function getActions()
{
$actions = [];
$users = $this->collectionFactory->create();
foreach($users as $user) {
$actions[] = [
'type' => $user->getUserName(),
'label' => $user->getName(),
'url' => $this->urlBuilder->getUrl('*/*/assignUser', ['user_id' =>
$user->getId()]),
];
}
return $actions;
}
}
Please someone look into it and help me to resolve this issue.