Currently I am working in Magento version-2.2.3. I have prepared one custom grid page using ui-component and added mass action on it which will be useful for admin. But now I want to hide Mass action option from users other then administrator role.

Any help will be appreciated. Please let me know.

1 Answer 1


I have searched a lot and after some R&D I found the solution by my own. Posting so that it will be helpful to others also.

In your UI component, add class on your massaction element shown as below:

<massaction name="listing_massaction" class="NameSpace\MyModule\Ui\MassAction">

In this class, we will write our logic to hide/show our MassAction dropdown.

Below is my MassAction.php file which I created under NameSpace/MyModule/UI/MassAction.php

namespace NameSpace\MyModule\Ui;

use Magento\Backend\Model\Auth\Session as AuthSession;

class MassAction extends \Magento\Ui\Component\MassAction
    protected $authSession;

    public function __construct(
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        AuthSession $authSession,
        array $data
    ) {
        $this->authSession = $authSession;
        parent::__construct($context, $components, $data);

    public function prepare()

        $adminuser = $this->authSession->getUser();
        if ($adminuser) {
            $roleData = $adminuser->getRole()->getData();
            if (!(strtolower($roleData['role_name']) == strtolower(\NameSpace\MyModule\Block\Menu::ADMINSTRATORS))) {
                $this->setData('config', '');

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.