Magento – Add grid to custom adminhtml page

admingridgrid-serlization

I am currently following a tutorial series which teaches you how to add pages and features within the admin section of your site. The current part I am on shows how to add a grid onto the page.

My problem is that when I get to the page it shows the magento header and footer found in the admin section but the content area is blank. In that blank area I expected to see a grid. I am not getting any error messages (they are on). I have my cache disabled. I am struggling through this tutorial as there are not many descriptions as to what the code is doing and when I should be testing code so I am trying to review code which is being extended and often getting confused.

From what I understand the code that should display the grid is the following

class Excellence_Employee_Adminhtml_EmployeeController
extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

Excellence/Employee/etc/adminhtml.xml

....
  <menu>
    <employee module="employee">
        <title>Employee</title>
        <sort_order>90</sort_order>
        <children>
            <items module="employee"><!--adds menu item-->
                <title>Manage Employees</title>
                <sort_order>0</sort_order>
                <action>adminhtml/employee</action><!--Link-->
            </items>

design/adminhtml/default/default/layout/employee.xml

<layout version="0.1.0">
  <employee_adminhtml_employee_index>
    <reference name="content">
        <block type="employee/adminhtml_employee" name="employee" />
    </reference>
  </employee_adminhtml_employee_index>
</layout>

.

class Excellence_Employee_Block_Adminhtml_Employee
extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function _construct()
{
    $this->_controller = 'adminhtml_employee';
    $this->_blockGroup = 'employee';
    $this->_headerText = Mage::helper('employee')->__('Employee Manager');
    $this->_addButtonLabel = Mage::helper('employee')->__('Add Employee');

    $this->_addButton('button1', array(
       'label'      => Mage::helper('employee')->__('Button Label1'),
       'onclick'    => 'setLocation(\'' . $this->getUrl('*/*/button1') . '\')',
       'class'      => 'add' 
    ));

    $this->_addButton('button2', array(
        'label'     => Mage::helper('employee')->__('Button Label2'),
        'onclick'   => 'setLocation(\'' . $this->getUrl('*/*/button2') . '\')',
        'class'     => 'remove'
    ));

    parent::_construct();
}
}

1 – am I looking at the correct blocks of code?

2a – if not where should I look?

2b – if so, why isn't the grid showing up?

If it helps the two tutorials that I have been following are Tut1 and Tut2. At the end of Tut1 is the time the author says the grid should be displayed and tut2 adds to that grid, I have added tut2 just incase there is some relevant information in there

Best Answer

It seems like potentially your admin xml layout fragment isn't getting picked up. In your module config.xml file do you have:

<config>
....
   <adminhtml>
     <layout>
       <updates>
         <employee>
           <file>employee.xml</file>
         </employee>
       </updates>
     </layout>
   </adminhtml>
...
</config>
Related Topic