As the other answers pointed out, you can use the Mage_Adminhtml_Block_Widget_Grid::addColumnAfter
to accomplish this.
However, what (most) does not mention other answers is that you must explicitly call Mage_Adminhtml_Block_Widget_Grid::sortColumnsByOrder
so that the columns are reordered .
The Mage_Adminhtml_Block_Widget_Grid::sortColumnsByOrder
method is called exclusively by the Mage_Adminhtml_Block_Widget_Grid::_prepareColumns
as follows:
/// app/code/core/Mage/Adminhtml/Block/Widget/Grid.php line 557 protected function _prepareColumns() { $this->sortColumnsByOrder(); return $this; }
This means that your derived class will have to do the same in order to re-sort the columns based on your new order. For example:
protected function _prepareColumns() { /// Let the parent add some columns /// Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract does add some parent::_prepareColumns(); /// Add some new columns $this->addColumnAfter('sort_order', array( 'header' => $this->__('Sort Order'), 'sortable' => true, 'index' => 'sort_order' ), 'frontend_label'); $this->addColumnAfter('attribute_group_name', array( 'header' => $this->__('Attribute Group'), 'sortable' => true, 'index' => 'attribute_group_name'), 'sort_order'); /// ! IMPORTANT ! Re-sort the columns with the new additions $this->sortColumnsByOrder(); return $this; }
Luke A. Leber
source share