I have one my admin grid in that edit time i add button in top action bar now in that on click i need to set custom action of controller

i try this but not working

                'class' => 'reset',
                'label' => __('Convert B2bCustomer'),
                'onclick' => 'setLocation(\'' . $buttonUrl . '\')'

enter image description here

enter image description here

  • Please check added answer and try. It will work
    – ZealousWeb
    Aug 26, 2021 at 11:39

1 Answer 1


Please add below code in your file and check.

Please change your controller action in function getButtonUrl()

$message = __('Are you sure you want to do this?');
        'label' => __('Convert B2bCustomer'),
        'id'    => 'convert',
        'on_click' => "confirmSetLocation('{$message}', '{$this->getButtonUrl()}')",
        'class' => 'convert primary' 
    ), -100

public function getButtonUrl()
    return $this->getUrl('routername/controller/action', ['id' => $this->getRequest()->getParam('id')]);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.