How to add custom attribute in customer grid in magento?
(ii) “Father Name”
(iii) “Mother Name”
Note:- you can download extension from this
Add custom customer attribute in customer grid in magento through custom module.
Note:- Firstly disable the cache from Cache Management tab and which is in System tab.
there are many steps to create the extension.
Step1:- Create Mywork_AddCustomAttributeOnCustomerGrid.xml file in app/etc/modules/.
where Mywork is Namespace and AddCustomAttributeOnCustomerGrid is Modulename.
[php]
<?xml version="1.0"?>
<config>
<modules>
<Mywork_AddCustomAttributeOnCustomerGrid>
<active>true</active>
<codePool>local</codePool>
</Mywork_AddCustomAttributeOnCustomerGrid>
</modules>
</config>
[/php]
Note:- 1) If you want to activate the extensions then use true otherwise false.
2) there are three code pool (a) local (b) core (c) community
when we create our own extension then we use the local code pool.
Step2:- Now create the config.xml file in app/code/local/Mywork/AddCustomAttributeOnCustomerGrid/etc/
[php]
<config>
<modules>
<Mywork_AddCustomAttributeOnCustomerGrid>
<version>1.0.0</version>
</Mywork_AddCustomAttributeOnCustomerGrid>
</modules>
<global>
<blocks>
<adminhtml>
<rewrite>
<customer_grid>Mywork_AddCustomAttributeOnCustomerGrid_Block_Adminhtml_Customer_Grid</customer_grid>
</rewrite>
</adminhtml>
</blocks>
<helpers>
<AddCustomAttributeOnCustomerGrid>
<class>Mywork_AddCustomAttributeOnCustomerGrid_Helper</class>
</AddCustomAttributeOnCustomerGrid>
</helpers>
</global>
</config>
[/php]
Step3:- Now create the Grid.php file in app/code/local/Mywork/AddCustomAttributeOnCustomerGrid/Block/Adminhtml/Customer/
[php]
<?php
class Mywork_AddCustomAttributeOnCustomerGrid_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
public function setCollection($collection) {
$collection->addAttributeToSelect(‘pan_number’);
$collection->addAttributeToSelect(‘father_name’);
$collection->addAttributeToSelect(‘mother_name’);
$this->_collection = $collection;
}
protected function _prepareColumns()
{
$this->addColumnAfter(‘pan_number’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Pan Number’),
‘width’ => ‘150’,
‘index’ => ‘pan_number’
),’email’);
$this->addColumnAfter(‘father_name’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Father Name’),
‘width’ => ‘150’,
‘index’ => ‘father_name’
),’pan_number’);
$this->addColumnAfter(‘mother_name’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Mother Name’),
‘width’ => ‘150’,
‘index’ => ‘mother_name’
),’father_name’);
return parent::_prepareColumns();
}
}
?>
[/php]
Step4:- Now create the Data.php file in app/code/local/Mywork/AddCustomAttributeOnCustomerGrid/Helper/
[php]
<?php
class Mywork_AddCustomAttributeOnCustomerGrid_Helper_Data extends Mage_Core_Helper_Abstract
{
}
?>
[/php]