CE1.9.2.4 - how to remove column from Customer Adminhtml Grid
-
01-10-2020 - |
Frage
I've successfully extended the core Customer Grid to show some custom attributes, but also need to remove the Country
column - the site in question only operates in one country, so it's unnecessary and takes up space on smaller screens.
I've tried:
protected function _prepareColumns(){
$this->removeColumn('billing_country_id'); // <---- this does not work :(
$this->addColumnAfter('department', array(
'header' => Mage::helper('customer')->__('Department'),
'index' => 'department'
),'email');
return parent::_prepareColumns();
}
but this does not seem to work. Is there another method that I can use?
Lösung
Removing the column doesn't work because at the moment when you are calling the removeColumn
method, the billing_country_id
column hasn't been added yet. That column gets added when Mage_Adminhtml_Block_Customer_Grid::_prepareColumns
is called, and that happens at the end of your method. You can try something like this:
protected function _prepareColumns() {
parent::_prepareColumns();
$this->removeColumn('billing_country_id'); // <--- hopefully this will work :)
$this->addColumnAfter('department', array(
'header' => Mage::helper('customer')->__('Department'),
'index' => 'department'
), 'email');
$this->sortColumnsByOrder();
return $this;
}
I've also added the sortColumnsByOrder
method call at the end in order to sort the newly added column too.