问题
I am creating custom module in Magento. Please tell me How to add multiple grid in Magento admin? Or add some data after or before the grid.
Thanks in advance
回答1:
Yes you can in following steps
Lets say you have module called Mycompany_Mail. And you want to create two grids called SentTray & RecvdTray
1) create a file Grid.php to create a class Mycompany_Mail_Block_Adminhtml_SentTray_Grid class under the folder Mycompany/Mail/Block/Adminhtml/SentTray/ and write the code to prepare columns inside it
2) create a file Grid.php to create a class Mycompany_Mail_Block_Adminhtml_RecvdTray_Grid class under the folder Mycompany/Mail/Block/Adminhtml/RecvdTray/ and write the code to prepare columns inside it
Note-1: do not create any other php file to initialize grid
Note-2: do not include blocks tag in your config.xml
3) Now, Lets create the controller file called MailController.php to create the class Mycompany_Mail_Adminhtml_MailController extends Mage_Adminhtml_Controller_Actionunder under the folder Mycompany/Mail/controllers/Adminhtml/
4) Lets create two actions one for accessing send tray and another for accessing recvd tray like shown below
public function sendTrayAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('Mycompany_Mail_Block_Adminhtml_SentTray_Grid'));
$this->renderLayout();
}
public function recvdTrayAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('Mycompany_Mail_Block_Adminhtml_RecvdTray_Grid'));
$this->renderLayout();
}
5) Now, link the above two actions with menu item. Thats is it.
回答2:
You may add several grids to the page.Otherwise you will need to create some sort of compound collection in _prepareCollection method. In this case, you'd better create some new model which would be dealing with data. Below is the structure you should go with to have multiple grids in one module.
- Namespace
- Module
- Block
- Adminhtml
- Submodule1
- Grid.php
- Submodule2
- Grid.php
- Submodule3
- Grid.php
来源:https://stackoverflow.com/questions/20239144/multiple-grid-in-magento-admin