I am trying to add a column for "trained_in" on the customer admin page inside my magento site.
I have the following code
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('trained_in')
->addAttributeToSelect('*')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('trained_in','')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
$this->setCollection($collection);
//code from Mage_Adminhtml_Block_Widget_Grid::_prepareCollection()
//since calling parent::_prepareCollection will render the code above useless
//and you cannot call in php parent::parent::_prepareCollection()
if ($this->getCollection()) {
$this->_preparePage();
$columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort);
$dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
$filter = $this->getParam($this->getVarNameFilter(), null);
if (is_null($filter)) {
$filter = $this->_defaultFilter;
}
if (is_string($filter)) {
$data = $this->helper('adminhtml')->prepareFilterString($filter);
$this->_setFilterValues($data);
}
else if ($filter && is_array($filter)) {
$this->_setFilterValues($filter);
}
else if(0 !== sizeof($this->_defaultFilter)) {
$this->_setFilterValues($this->_defaultFilter);
}
if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) {
$dir = (strtolower($dir)=='desc') ? 'desc' : 'asc';
$this->_columns[$columnId]->setDir($dir);
$this->_setCollectionOrder($this->_columns[$columnId]);
}
if (!$this->_isExport) {
$this->getCollection()->load();
$this->_afterLoadCollection();
}
}
return $this;
}
/**
* override the _prepareColumns method to add a new column after the 'email' column
* if you want the new column on a different position just change the 3rd parameter
* of the addColumnAfter method to the id of your desired column
*/
protected function _prepareColumns(){
$this->addColumnAfter('trained_in', array(
'header' => Mage::helper('customer')->__('Trained In'),
'index' => 'trained_in'
),'name');
return parent::_prepareColumns();
}
}
However on the front end the column is showing as empty next to each customer but when i dump out the collection it shows ['trained_in'] => 6? A little context :
Trained in was added as a custom attribute inside of magento, and it is also a multiple select field i wish to display.