I have created a custom grid on customer view in admin

 protected function _construct()


are used to get sorter , pager and filters

How can i add new custom button here above the grid?

enter image description here

2 Answers 2


In your grid.php (where grid columns and sorter etc)

 public function getMainButtonsHtml()
        $html = parent::getMainButtonsHtml();//get the parent class buttons
        $addButton = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')
            'label'     => 'Add',
            'onclick'   => "setLocation('#')",
            'class'   => 'task'
        return $addButton.$html;



You need to check magento 2 default functionlity to add button in any grid.

                    'label' => __('YOUR TEXT'),
                    'onclick' => 'setLocation(\'' . YOUR ACTION URL . '\')',
                    'class' => 'add'
  • Already tried not working Sep 16, 2016 at 13:33
  • Is this code give any error then specify that. Sep 16, 2016 at 13:34
  • that is not any add method in 'magento\module-backend\Block\Widget\Grid\Extended.php' , anyways found the solution thanks for answering Sep 16, 2016 at 13:37
  • @VishwasBhatnagar Can you please tell us the way to add button in grid . The above code is not working properly. Feb 22, 2018 at 10:29
  • @VinaySikarwar Have you tried my solution Feb 26, 2018 at 6:13

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.