2

I'd like to know how to remove a column in the sales order grid using an layout update.

I have the following layout update for add a column to the sales order grid. The Something column gets added as the first column and removeColumn (to remove the Order # column ) action does nothing because when this layout update is performed, there are no columns added yet.

<layout>
    <sales_order_grid_update>
        <reference name="sales_order.grid">
            <!-- removeColumn doesn't work because no columns have been added yet -->
            <action method="removeColumn">
                <columnId>real_order_id</columnId>
            </action>
            <!-- This column gets added as the first column in the grid -->
            <action method="addColumnAfter">
                <columnId>new_column</columnId>
                <arguments>
                    <header>Something</header>
                    <index>new_column</index>
                    <type>text</type>
                </arguments>
            </action>
        </reference>
    </sales_order_grid_update>
    <adminhtml_sales_order_grid>
        <update handle="sales_order_grid_update" />
    </adminhtml_sales_order_grid>
    <adminhtml_sales_order_index>
        <update handle="sales_order_grid_update" />
    </adminhtml_sales_order_index>
</layout>

Is it possible to remove one of the default columns of the sales order grid with a layout update? If so, is this the right XML for it? I know I can remove that column with an observer or by rewriting the appropriate block class, but I'd like to see if an layout update can achieve the same while being as minimally intrusive as possible.

This is the approach I'm taking: http://www.atwix.com/magento/column-to-orders-grid/.

2
  • I've never modified the sales grid with XML alone - I'm not sure if this is possible... This is the standard way to make changes to the sales grid.
    – zigojacko
    Commented Nov 14, 2014 at 8:12
  • It's possible add columns with an XML update (some PHP code may be required to populate the added column). The above does just that. I've put a link that describes my approach.
    – laketuna
    Commented Nov 14, 2014 at 15:24

1 Answer 1

1

This is what you're getting snagged on:

  • The grid columns are setup in Mage_Adminhtml_Block_Widget_Grid::beforeToHtml

So as you observed, removing the column via layout XML does nothing, because the column doesn't exist until the very last moment before being rendered.

If this is for a specific scenario, you could try to extend the target block to call prepareGrid in _construct; not sure of the repercussions there (ie: it is also called in the export handlers).


As for some pure XML solution, I don't see that as possible. It also doesn't seem the place of layout XML to define this. For example, how would you express an array of values, as is often seen when specifying the filter_condition_callback property? Though delivered as a visual piece, grid columns are really more about the data than its appearance -- and this is why layout XML seems an inappropriate fit. The fact that Atwix shows you HOW to manage them with layout XML is really just a byproduct of Magento's neat ability to translate XML into block actions.

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.