0

I'd like to know how to edit an existing column in the orders grid.

For example, I've added my own columns using an observer by joining the sales_flat_order_grid table with the sales_flat_order table to get the fields I need. However, if I try to filter based on the increment_id, then the filter fails because it is coming across an ambiguous field since both tables have that same field.

I'm trying to add a "filter_index" with the value "main_table.increment_id" to that column. So I'm able to use an event observer to grab the block based on the "core_block_abstract_to_html_after" event but I think this event is fired too late for the filter to actually be set. Also, I tried the "core_block_abstract_prepare_layout_before" event but the column doesn't exist at that point.

What other event can I use?

Note: I've tried rewriting the sales grid with my own and I'm able to get this working via the following code in the _prepareColumns() method but I'm trying to do it via the observer since that won't conflict with any other extensions:

protected function _prepareColumns()
{
    parent::_prepareColumns();

    $this->addColumnAfter('custom_column', array(
        .....
    ), 'shipping_name');

    $this->getColumn('real_order_id')
        ->setData('filter_index', 'main_table.increment_id');

}

Thanks.

1
  • Try overriding the Mage_Adminhtml_Block_Sales_Order_Grid.php
    – Sukeshini
    Mar 27, 2014 at 4:05

1 Answer 1

1

Sadly there are no events fired that would work on all the grid options, such as export and normal display. As _prepareColumns is called from _prepareGrid which is called from a multitude of places.

protected function _prepareGrid()
{
    $this->_prepareColumns();
    $this->_prepareMassactionBlock();
    $this->_prepareCollection();
    return $this;
}

What I would suggest is rewrite the class Mage_Adminhtml_Block_Sales_Order_Grid and fire your own event before and after the call to the parent _prepareColumns. This way if you do have some conflicts in the future you should be able to hook onto these events and solve your conflicts easily. A good example of this, though it is not columns but tabs, is the event adminhtml_catalog_category_tabs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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