How to display Your custom table values in Admin Grid:
Based on above steps you can access your table as like magento way. But you have show your table values as a admin grid in magento. Then we have to create our block files.
Here am going to give link from admin-> sales -> Jute Travelinfo tab in admin section.
For that we have to create adminhtml xml file like below
How to create admin custom menu tab in admin section:
I need to show my custom tab under the admin – sales tab. For that i have created my etc/adminhtml.xml file like below
<?xml version=”1.0″?>
<config>
<menu>
<sales>
<children>
<jute_travelinfo translate=”title” module=”jute_travelinfo”>
<sort_order>999</sort_order>
<title>Jute – Travelinfo</title>
<action>adminhtml/travelinfo/</action>
</jute_travelinfo>
</children>
</sales>
</menu>
</config>
Here green color mention code is calling my controller. When admin onclick the link, the page redirect to below controller, I have declared my controller like below
app\code\community\Jute\Travelinfo\controllers\Adminhtml\ TravelinfoController.php
class Jute_Travelinfo_Adminhtml_TravelinfoController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->_title($this->__(‘Travelinfo’))->_title($this->__(‘Jute Travelinfo’));
$this->loadLayout();
$this->_setActiveMenu(‘sales/sales’);
$this->renderLayout();
}
public function gridAction()
{
$this->loadLayout();
$this->getResponse()->setBody(
$this->getLayout()->createBlock(‘travelinfo_travelinfo/adminhtml_travelinfo_travelinfo_grid’)->toHtml()
);
}
}
Create Block File:
Here am going to create my block file. Under this block file, am going to call my custom phtml file like below
class Jute_Travelinfo_Block_Travelinfo extends Mage_Adminhtml_Block_Template
{
public function _construct() {
parent::_construct();
}
}
Then in grid section if you want to add any extra button or remove any button then you have mention in below file. In my grid i have added onmore button called Import button. This button redirect admin to import contoller action. Also i don’t want add button here, so that i have removed from the grid section
Jute\Travelinfo\Block\Adminhtml\Jute\Travelinfo.php
class Jute_Travelinfo_Block_Adminhtml_Jute_Travelinfo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_blockGroup = ‘travelinfo_travelinfo’;
$this->_controller = ‘adminhtml_travelinfo_travelinfo’;
$this->_headerText = Mage::helper(‘travelinfo_travelinfo’)->__(‘Jute Travelinfo’);
$data = array(
‘label’ => ‘Import Travelinfo Code’,
‘onclick’ => “setLocation(‘”.$this->getUrl(‘*/*/import’).”‘)”
);
$this->addButton (‘Import Travelinfo Code’, $data, 0, 100, ‘header’, ‘header’);
parent::__construct();
$this->_removeButton(‘add’);
}
}
………………………………………………………………………………………………………………………………………………………………………………………………..
Corner of Blog :
“Save Paper Save Tree”
………………………………………………………………………………………………………………………………………………………………………………………………..