How to create a custom grid from scratch

inchoo orders

We received a request from a client where they wanted to implement an expanded order grid while still keeping the default Magento’s one. For this example we’ll create a new module named Inchoo Orders.

Step 1.

Create new module in etc/modules called Inchoo_Orders.xml

<?xml version="1.0"?>

Step 2.

Next thing we’ll do is create folder Inchoo/Orders inside app/code/community and inside we’ll make few folders: Block, controllers, etc, Helper.


Step 3.

Create config.xml inside etc folder.

<?xml version="1.0"?>
                        <inchoo_orders before="Mage_Adminhtml">Inchoo_Orders_Adminhtml</inchoo_orders>

Step 4

Create adminhtml.xml file inside etc folder which will add a link to our orders page in magento admin panel.

<?xml version="1.0"?>
                <inchoo_orders translate="title" module="inchoo_orders">
                    <title>Orders - Inchoo</title>

Step 5

Create blank helper class.

class Inchoo_Orders_Helper_Data extends Mage_Core_Helper_Abstract

Step 6

Next step is to create controller for our grid.

class Inchoo_Orders_Adminhtml_OrderController extends Mage_Adminhtml_Controller_Action
    public function indexAction()
        $this->_title($this->__('Sales'))->_title($this->__('Orders Inchoo'));
    public function gridAction()
    public function exportInchooCsvAction()
        $fileName = 'orders_inchoo.csv';
        $grid = $this->getLayout()->createBlock('inchoo_orders/adminhtml_sales_order_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
    public function exportInchooExcelAction()
        $fileName = 'orders_inchoo.xml';
        $grid = $this->getLayout()->createBlock('inchoo_orders/adminhtml_sales_order_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));

Step 7

Next thing we do is create grid container in Block/Adminhtml/Sales/Order.php

class Inchoo_Orders_Block_Adminhtml_Sales_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
    public function __construct()
        $this->_blockGroup = 'inchoo_orders';
        $this->_controller = 'adminhtml_sales_order';
        $this->_headerText = Mage::helper('inchoo_orders')->__('Orders - Inchoo');

Step 8

Last step is making grid class in Block/Adminhtml/Sales/Order/Grid.php

class Inchoo_Orders_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
    public function __construct()
    protected function _prepareCollection()
        $collection = Mage::getResourceModel('sales/order_collection')
            ->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id AND a.address_type != \'billing\'', array(
                'city'       => 'city',
                'country_id' => 'country_id'
            ->join(array('c' => 'customer/customer_group'), 'main_table.customer_group_id = c.customer_group_id', array(
                'customer_group_code' => 'customer_group_code'
                'CONCAT({{customer_firstname}}, \' \', {{customer_lastname}})',
                array('customer_firstname' => 'main_table.customer_firstname', 'customer_lastname' => 'main_table.customer_lastname'))
                '(SELECT GROUP_CONCAT(\' \',
                    FROM sales_flat_order_item x
                    WHERE {{entity_id}} = x.order_id
                        AND x.product_type != \'configurable\')',
                array('entity_id' => 'main_table.entity_id')
        return $this;
    protected function _prepareColumns()
        $helper = Mage::helper('inchoo_orders');
        $currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
        $this->addColumn('increment_id', array(
            'header' => $helper->__('Order #'),
            'index'  => 'increment_id'
        $this->addColumn('purchased_on', array(
            'header' => $helper->__('Purchased On'),
            'type'   => 'datetime',
            'index'  => 'created_at'
        $this->addColumn('products', array(
            'header'       => $helper->__('Products Purchased'),
            'index'        => 'products',
            'filter_index' => '(SELECT GROUP_CONCAT(\' \', FROM sales_flat_order_item x WHERE main_table.entity_id = x.order_id AND x.product_type != \'configurable\')'
        $this->addColumn('fullname', array(
            'header'       => $helper->__('Name'),
            'index'        => 'fullname',
            'filter_index' => 'CONCAT(customer_firstname, \' \', customer_lastname)'
        $this->addColumn('city', array(
            'header' => $helper->__('City'),
            'index'  => 'city'
        $this->addColumn('country', array(
            'header'   => $helper->__('Country'),
            'index'    => 'country_id',
            'renderer' => 'adminhtml/widget_grid_column_renderer_country'
        $this->addColumn('customer_group', array(
            'header' => $helper->__('Customer Group'),
            'index'  => 'customer_group_code'
        $this->addColumn('grand_total', array(
            'header'        => $helper->__('Grand Total'),
            'index'         => 'grand_total',
            'type'          => 'currency',
            'currency_code' => $currency
        $this->addColumn('shipping_method', array(
            'header' => $helper->__('Shipping Method'),
            'index'  => 'shipping_description'
        $this->addColumn('order_status', array(
            'header'  => $helper->__('Status'),
            'index'   => 'status',
            'type'    => 'options',
            'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
        $this->addExportType('*/*/exportInchooCsv', $helper->__('CSV'));
        $this->addExportType('*/*/exportInchooExcel', $helper->__('Excel XML'));
        return parent::_prepareColumns();
    public function getGridUrl()
        return $this->getUrl('*/*/grid', array('_current'=>true));

Our new custom orders page can be accessed by going to Sales -> Orders – Inchoo in admin panel.

link in admin

End result should be something like this:

inchoo orders grid

Interested in hiring us?

Have a chat with us. You would be surprised how small changes can make your business even more successful.


  1. Hi,
    I follow all instruction at last it showing page not found in localhost wamp which I newly installed, please help me

  2. Fatal error: Call to a member function setSaveParametersInSession() on a non-object in /opt/lampp/htdocs/layoutmagento/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php on line 66

    I have error in the same code you have writte above. Please help me

  3. Hi

    i have error in the same you have written above

    Fatal error: Call to a member function setSaveParametersInSession() on a non-object in /opt/lampp/htdocs/layoutmagento/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php on line 66

    Please help.

  4. Fatal error: Call to a member function setSaveParametersInSession() on a non-object in /opt/lampp/htdocs/layoutmagento/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php on line 66

  5. I have the blank screen error. I narroved it to the line


    . If I comment out the line, I have at least Magento Header and footer and blank white between. So there’s something with the fuction or the Grid.php. Version is What have changed?

  6. Hi Vedran

    I have used this and it is working fine.
    I want to make some checks in query by using my custom table. Could you please guide me how can i implement this in grid.php ?

    Thanks in advance

    1. Hai I am also seeking the requirement I need to display the orders from custom created tables. Did u got the idea Please share if any code available to implement. Thanks in advance

  7. HI first of all thanks for such a nice post.It works perfect.

    But i have a some confusion in the config.xml file.

    in that there is a model


    we have defined but we dont have a model class for this so why dont it has raise a errot .
    Please tell me i just learning magento extensions


  8. This helped so much!!! For those having issues with the 404 page, you most likely do not have the OrderController.php in the right folder. It should be controllers/Adminhtml/OrderController.php

  9. Perfect – Was looking for something like this for ages. I can confirm this works perfectly on the new version of 1.8.1 as well.

  10. i try to use this code but not working and give black screen.

    please Vedran Sola why this not work??

    thanks in advanced

  11. For those getting a 404 Not Found Error when trying to access the grid, I found the issue was where I put my OrderController.php file. It needs to be Inchoo/Orders/controllers/Adminhtml/OrderController.php

    Originally I had put it in Inchoo/Orders/controllers/OrderController.php and this doesn’t work.

  12. Hi,
    This is very good extension. In our custom grid orders are showing but it better link provide to the orders to the order detailed page. Can you please guide the hyperlink to redirect the order page when we click on that order.

  13. I am gettign this error whenever I tried to open this module from admin site
    Parse error: syntax error, unexpected ‘Â Â Â Â public’ (T_STRING), expecting function (T_FUNCTION) in C:\xampp\htdocs\magento\app\code\community\Inchoo\Orders\controllers\Adminhtml\OrderController.php on line 9

    Can anyone help me for that

  14. I make my own module using your concept but grid content are not shown… help me out to fix this problem

  15. Thank you very much for your post!
    Anyone know how to generate in a cronjob the csv with this content?
    is for integration with a sales soft
    thankyou in advance

  16. Sam at RocketTheme helped me out with the database prefix issue.

    Change out the table name:


    With this:


    That will retrieve any prefix for your current install.

  17. Looks like this adds the row url, which I just pulled from the core Grid.php file:

    public function getRowUrl($row)
    if (Mage::getSingleton(‘admin/session’)->isAllowed(‘sales/order/actions/view’)) {
    return $this->getUrl(‘*/sales_order/view’, array(‘order_id’ => $row->getId()));
    return false;

    That added just above the grid url code near the end.

  18. Got things working and this is a great walk through.

    Two things I noticed are that a database table prefix needs to be defined in the Grid.php file code and that the row does not link to the order details.

    Is it possible to get the row linked to the order details?

  19. Y i need to just make a file in helper when there is no data in it ? I am just declaring the file & not writing any content in it.

  20. Hi,
    I can see the Order – Inchoo under the Sales tab in the admin. However when I click on it, it gives me a 404 error.
    Below is the link it is pointing to:

    Is this link correct? I have verified the file structure and it is same as mentioned above.
    I am guessing something is wrong with my etc/adminhtml.xml.

    Orders – Bakery

    Please advice.


  21. Hi,
    I am running magento 1.7, and followed the steps above to create a new grid. However when I click on it from the admin page, I get a 404, page not found error. I don’t see the new grid details :((.
    Please help.


  22. I got same errors so I just changed few lines.

    Wrong :
    class Inchoo_Orders_Adminhtml_OrderController extends Mage_Adminhtml_Controller_Action

    Right :
    class Inchoo_Orders_Adminhtml_OrdersController extends Mage_Adminhtml_Sales_OrderController


    in adminhtml.xml

    Orders – Inchoo

  23. Hello ,

    I am facing the same problem as of Hissam Roohi.

    What could be the issue?? I think that might be the issue due to some wrong configuration. Can you please let me know what could be the issue

  24. When i click the Orders- Inchoo sub menu , i am getting the error ‘The page you requested was not found, and we have a fine guess why.’

    After clicking it is redirecting the below url :


    @Vedran Sola -Can you please help me out

  25. Data.php is helper and controller class should go to controllers/Adminhtml/Order.php

  26. Hey Vedran,
    This looks very interesting. I got lost at steps 5 and 6. What files should contain the blank helper class and the controller for our grid?

  27. @Kieran

    gridAction is being called by getGridUrl method in Grid.php and its purpose is to enable grid filtering using ajax.

  28. Hi,

    I have followed your guide but when I click on the link it simple gives me a blank screen not showing the grid. One thing i was wondering, where does it call the gridAction from the controller?

  29. Very interesting. For my experience a current problem is to create a master/details grid. Have you got a road to?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.