Add Attributes to Magento Admin Product Grid
It’s possible within Magento to add custom attributes to your products at any time and these attributes can be used as very effective filters on the frontend. They are also very useful in the admin when it comes to searching through hundreds and perhaps thousands of products. The good news is that you can add these columns very easily be simply extending any of the product grid files within your adminhtml blocks.
I’ll show you how to add both text and dropdown attributes to your admin product grid.
Extend your grid.php file
Every time you do this, you need to extend grid.php so we can rewrite the _prepareColumns() method. In my example below I want to add extra attributes to the grid that appears when choosing simple products to add to your bundle products. The file is located here:
app > code > core > Mage > Bundle > Block > Adminhtml > Catalog > Product > Edit > Tab > Bundle > Option > Search > Grid.php
Find it? I think the holy grail is in there somewhere…. Anyway, the next stage is to register the rewrite in your module’s config.xml:
<global>
<blocks>
<custombundle>
<class>Creare_Custombundle_Block</class>
</custombundle>
<bundle>
<rewrite><adminhtml_catalog_product_edit_tab_bundle_option_search_grid>Creare_Custombundle_Block_Bundle_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option_Search_Grid</adminhtml_catalog_product_edit_tab_bundle_option_search_grid>
</rewrite>
</bundle>
</blocks>
</global>
Add text attribute column
The next stage is simply to add the columns that are required. In this example I’m adding a text attribute I created called ‘height’. For a text attribute it is quite simple, simply add this to the _prepareColumns() method:
$this->addColumn('height', array(
'header' => Mage::helper('sales')->__('Height'),
'width' => '100px',
'index' => 'height'
));
The method addColumn() is in Mage_Adminhtml_Block_Widget_grid class, it creates a HTML block based on the column ID you provide in the first parameter, and the array of arguments you pass through. The column ID can be anything you wish as long as it is unique in this grid. It’s good practice to name it the same as your attribute ID. The ‘index’ key in the array needs to be your attribute ID. The other two are self-explanatory.

The end result is exactly what you’d expect. Type your value in an filter your products accordingly.
Add dropdown/multi-select attribute column
Adding a dropdown option requires an extra step because you need to feed in a list of values to select from. As the attribute values in a dropdown attribute are numbers it is much more user friendly to do it this way because you can use the label. In this example I’m using a dropdown attribute I created called ‘item_type’:
$item_types = array();
foreach (Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'item_type')->getSource()->getAllOptions() as $type)
{
$item_types[$type['value']] = $type['label'];
}
$this->addColumn('item_type', array(
'header' => Mage::helper('sales')->__('Item Type'),
'width' => '180px',
'index' => 'item_type',
'type' => 'options',
'options' => $item_types
));
I’m doing two things here. Firstly I’m creating an array with the attribute value as the key, and the label as the value. Still following? Then, I provide that array to the ‘options’ key in the array we send to our addColumn() function.

This will then provide the column with a usable dropdown header for filtering your products. This exact same logic can be applied to any product grid in the Magento admin. Similar logic also applies for any other model grids too.
Hope this comes in useful, thanks for reading.
Adam is Ecommerce Manager and a PHP developer at Creare Group. Adam is responsible for training Magento development within the company. Follow Adam on Twitter: http://twitter.com/adampmoss. - Read my other posts.

Great post, very useful for most people using the Magento administration, There are a couple of good Free extension that offer similar features that we utilise. Our favourite is enhanced grid with editor but even with all the features it does offer we have still had to add columns to bring in inventory values such as ‘instock/outofstock’ but well worth a look.
http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html
Cool extension Ryan, thanks for sharing!