Magento – Add Export to csv button in form

This code is add button export to csv in form same as  grid page.

public function getElementHtml()
{

$buttonBlock = $this->getForm()->getParent()->getLayout()->createBlock(‘adminhtml/widget_button’);

$params = array(
‘website’ => $buttonBlock->getRequest()->getParam(‘website’)
);

$data = array(
‘label’     => Mage::helper(‘adminhtml’)->__(‘Download sample CSV’),
‘onclick’   => ‘setLocation(\”.Mage::helper(‘adminhtml’)->getUrl(“*/*/exportCsv”, $params) . ‘conditionName/\’ +\’/tablerates.csv\’ )’,
‘class’     => ”,
);
$html = $buttonBlock->setData($data)->toHtml();
return $html;
}

Enjoy.. 🙂

Advertisements