Jak wskazano w innych odpowiedziach, można to zrobić, korzystając z metody Mage_Adminhtml_Block_Widget_Grid::addColumnAfter
.
Jednak na większość (innych) odpowiedzi nie wspomina się, że należy jawnie wywołać Mage_Adminhtml_Block_Widget_Grid::sortColumnsByOrder
, aby zmienić kolejność kolumn na.
Sposób Mage_Adminhtml_Block_Widget_Grid::sortColumnsByOrder
nazywany jest wyłącznie metodą Mage_Adminhtml_Block_Widget_Grid::_prepareColumns
następująco:
/// app/code/core/Mage/Adminhtml/Block/Widget/Grid.php line 557
protected function _prepareColumns()
{
$this->sortColumnsByOrder();
return $this;
}
Oznacza to, że klasa pochodna będzie musiał zrobić to samo w celu ponownego sortowania kolumn w oparciu o nową zamawiania. Na przykład:
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;
}
To działa. – jruzafa
uważaj, kolejność wywoływania tego przed rodzicem może być ważna, zobacz odpowiedź Praful Rajput – peedee