3

In Magento 2.2.5, I am creating admin grid by following this tutorial(Using layout Block method. Not UI Component).

In that I have a add button. I can't remove it. I need to remove it and add a new button with custom url. How to achieve this.

Screenshot:

Screenshot

  • Can you share your code? – Chirag Patel Oct 22 '18 at 9:21
6

You can use update

parent::_construct();
$this->buttonList->update('save', 'onclick', 'setLocation(\'' . $this->getUrl('*/*/<youraction>') . '\')');
| improve this answer | |
2

Try using this code

    parent::_construct();
    $this->removeButton('add');

    $this->buttonList->add(
            '<your name>',
            [
        'label' => __('<your label>'),
        'class' => 'save',
        'onclick' => 'setLocation(\'' . $this->getUrl('*/*/<youraction>') . '\')',
        'style' => '    background-color: #ba4000; border-color: #b84002; box-shadow: 0 0 0 1px #007bdb;color: #fff;text-decoration: none;'
            ]
    );

Hope that will help you.

| improve this answer | |
  • Yes, It is working. I have tried this but before parent::_construct(); i added this remove button code. So It is not worked. – Saravanan DS Oct 16 '18 at 7:42
0

Try using this code

     protected function _construct()
        {
            $this->_objectId = 'row_id';
            $this->_blockGroup = '[Vendor_name]_[module_name]';
            $this->_controller = 'adminhtml_[Controller_name]';
            parent::_construct();

// for remove btn

            $this->buttonList->remove('save');
            $this->buttonList->remove('back');
            $this->buttonList->remove('reset');

/////  for update btn name

            $this->buttonList->update('save', 'label', __('[Updateed_btn_name]'));

/// for add new custome btn

            $this->addButton(
                        '<custome_btn_name>',
                        [
                            'label' => __('Btn_name_to_show'),
                            'on_click' => sprintf("location.href = '%s';", $this->getUrl('[Route_name]/[controller_name]/[file_name]')),
                            'class' => 'primary',
                            'level' => 1
                        ]
                    );
        }

I Hope This Helps You.

| improve this answer | |
  • If it's works for you VOTE UP – Msquare Oct 20 '19 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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