在产品选项卡中移动“添加新”按钮
-
16-10-2019 - |
题
我创建了一个自定义模块,该模块在网格中显示数据。如何将“添加新速率”按钮从模块标头移动到网格?我还没有尝试任何事情,因为我不知道从哪里开始。
解决方案
即使我看不到这一点(但也许我不是那样的艺术)也可以轻松完成。首先,您需要从网格容器块中删除添加按钮。这应该是块: {Namespace}/{Module}/Block/Adminhtml/{Entity}.php
. 。在 __construct
方法添加此行:
$this->removeButton('add');
现在,您需要在搜索按钮附近添加一个按钮。为此,您应该添加一种称为的方法 getMainButtonsHtml
在您的网格块中。这是 {Namespace}/{Module}/Block/Adminhtml/{Entity}/Grid.php
public function getMainButtonsHtml()
{
$html = parent::getMainButtonsHtml();//get the parent class buttons
$addButton = $this->getLayout()->createBlock('adminhtml/widget_button') //create the add button
->setData(array(
'label' => Mage::helper('adminhtml')->__('Add'),
'onclick' => "setLocation('".$this->getUrl('*/*/new')."')",
'class' => 'task'
))->toHtml();
return $addButton.$html;
}
而已。快乐按钮对齐。