I am facing an issue of adding a column on customer grid and showing values in that column.
Here is the observer code that I have been trying to show the column:-
if ($block->getType() == 'adminhtml/customer_grid') {
$customer = $observer->getCustomer();
$collection = Mage::getResourceModel('customer/customer_collection');
$block->addColumnAfter('mobile', array(
'header' => 'Mobile No.',
'type' => 'text',
'index' => 'mobile',
), 'email');
}
This adds the column but no values are shown under that.
Best Answer
To add a column to the customer grid, you need to override 2 things in the block
Mage_Adminhtml_Block_Customer_Grid
._prepareCollection
- to add your attribute in the collection_prepareColumns
- to add the column in your grid.For this you should create a new extension. Let's call it
Easylife_Customer
. For this you will need the following files:app/etc/module/Easylife_Customer.xml
- the declaration fileapp/code/local/Easylife/Customer/etc/config.xml
- the configuration fileapp/code/local/Easylife/Customer/Block/Adminhtml/Customer/Grid.php
- your own version of the customer grid. Read my comments in the code:Clear the cache and you should be ready.