Usually we need to add to the Order Grid some column, so let take this as example.

There are 3 ways to do that:

  1. Rewrite the grid block in our custom module
  2. Use an observer on the event core_block_abstract_prepare_layout_before
  3. Use a Layout update

(let don't consider the alteration of the collection to make things more easy)

  • First method is the most powerful but It leads to conflict in the scenarios.
  • Second method is in IMHO resource consuming as we are adding an extra code step for every block we are going to render
  • Third step is a layout update so should be the most advisable ... but are we sure it will work always ?

Other consideration are welcome

Method 1: - http://inchoo.net/ecommerce/magento/programming-magento/adding-customer-group-column-to-sales-grid-in-magento/
Method 2: - http://www.atwix.com/magento/add-column-to-customers-grid-alternative-way/
Method 3: - http://www.atwix.com/magento/column-to-orders-grid/


Best practice to add a column to the backend grid is of course implementation of event-observer method. But question arises which event is used for the purpose? And one of the Answer is core_block_abstract_to_html_before

Suppose say you have implemented observer model for above event with method coreBlockAbstractToHtmlBefore.


public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer)

    /** @var $block Mage_Core_Block_Abstract */
    $block = $observer->getEvent()->getBlock();
    if ($block->getId() == 'customerGrid')
        // Add the attribute as a column to the grid
                'header' => $helper->__('Custom Grid Element'),
                'align' => 'center',
                'width' => '80px',
                'type' => 'text',
                'options' => array(
                'default' => '',
                'index' => 'custom_grid_element',
                'renderer'  => ''

        // Set the new columns order.. otherwise our column would be the last one

Above is just an example for adding custom grid element to the Customer grid. You can deploy the very same technique for Sales grid as well.

| improve this answer | |
  • Any reason to choose core_block_abstract_to_html_before instead of core_block_abstract_prepare_layout_before – Fra May 21 '13 at 5:12
  • Hope this helps: "Just as with the _prepareLayout method, the before and after html rendering methods have analogous global system events core_block_abstract_to_html_before core_block_abstract_to_html_after Unlike the lifecycle callbacks, these events will fire regardless of the cache state of a block. So, if you were trying to use _beforeToHtml but its cache behavior was problematic, setting a listener for core_block_abstract_to_html_before should get you where you need to go." REFER: alanstorm.com/magento_listener_lifecycle_block – MagePsycho May 21 '13 at 6:15
  • When using the "core_block_abstract_to_html_before" event for my observer, I was not able to do any sorting or filtering on my custom column. Instead I had to use the "core_block_abstract_prepare_layout_after" event, as described here: magento.stackexchange.com/a/4720/3830 – Louis B. Sep 12 '16 at 12:08

If you want to use on observer try adminhtml_block_html_before instead of core_block_abstract_to_html_before

You could also use your module adminhtml layout.xml

    <?xml version="1.0"?>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <arguments module="sales" translate="header">
                    <header>MagePal #</header>
        <update handle="add_order_grid_column_handle" />
        <update handle="add_order_grid_column_handle" />

See Add new field to administration orders grid

| improve this answer | |
  • When using the "core_block_abstract_to_html_before" event for my observer, I was not able to do any sorting or filtering on my custom column. Instead I had to use the "core_block_abstract_prepare_layout_after" event, as described here: magento.stackexchange.com/a/4720/3830 – Louis B. Sep 12 '16 at 12:09

The best way to add a column to the order grid is to create an observer for the sales_order_resource_init_virtual_grid_columns event. Just add a column to the sales_flat_order_grid table in your install script and use this event to store the data directly into the table at every order save. This way there is no need for any joins when showing the grid to the user. For more details on how to setup the column see http://www.ecomdev.org/2010/07/27/adding-order-attribute-to-orders-grid-in-magento-1-4-1.html

| improve this answer | |
  • the event sales_order_resource_init_virtual_grid_columns is never triggered during order grid load – Fra May 20 '13 at 10:16
  • Thats correct, it's triggered at saving the order and copies to correct data to the sales_flat_order_grid table that is used when displaying the sales/order grid in the admin. Because all data is stored in a single database there is only a single select needed to collect the data (no joins that create heavy queries every time the grid is loaded). – Vladimir Kerkhoff May 20 '13 at 17:15
  • If I just open the Order grid page it is not triggered – Fra May 21 '13 at 5:12
  • 1
    No, again the event is triggered at order save! It is used to generate to select/insert into the sales_flar_order_grid table. The Order grid page only displays the data and the collection is read from the sales_flat_order_grid table. – Vladimir Kerkhoff May 21 '13 at 6:10
  • Any hint for customising also invoice grid and credit memo grid? Thanks. – ermannob Sep 4 '15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.