Add custom column and get custom renderer value in Magento grid

Magento
This post is helpful to add custom column and get custom renderer value in Magento grid admin. In /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php file. [php] <?php protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); //$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('postcode')); // Added my developer //$collection->getSelect()->joinLeft('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id','method'); // Added my developer $collection->getSelect()->joinLeft('sales_flat_order_status_history', 'main_table.entity_id = sales_flat_order_status_history.entity_id','comment'); // Added my developer $this->setCollection($collection); return parent::_prepareCollection(); } ?> [/php] [php] <?php protected function _prepareColumns() { /**** start *****/ $this->addColumn('comment', array( 'header' => Mage::helper('sales')->__('comment'), 'index' => 'comment', 'filter' => false, 'sortable' => false, 'renderer' => 'Mage_Adminhtml_Block_sales_Order_Renderer_Red', )); /**** end ******/ } ?> [/php] Make directory called Renderer inside directory where your Grid.php is located and make file Red.php Make class Mage_Adminhtml_Block_Catalog_Product_Renderer_Red extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract [php] <?php class Mage_Adminhtml_Block_sales_Order_Renderer_Red extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { public function render(Varien_Object $row) { $value = $row->getData($this->getColumn()->getIndex()); return '<span style="color:…
Read More