I wanted to add custom column called brands(dropdown) in magento product grid in backend.I achieved this task but the issue is when i start filter the brands the column brands disappers and when i refresh the page then comes back.can any one please help me.
Here is my code.
in _prepareCollection() function i added
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->addAttributeToSelect('brands'); // added by me
in _prepareColumns()
$brands = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id','attribute_code');
foreach($brands as $brand):
if($brand->getAttributeCode() == 'brands')
$brand_options[$brand->getOptionId()] = $brand->getValue();
endforeach;
$this->addColumn('brands',
array(
'header'=> Mage::helper('catalog')->__('Brands'),
'width' => '10px',
'index' => 'brands',
'type' => 'options',
'sortable' => false,
'options' => $brand_options,
));
Best Answer
First add the add new function on grid.php getAttributeOptions
then add modify
'final_index' =>'brands',