Magento Grid Column Renderer

In previous post we will learn how to show grid in magento admin and remove add button from grid listing view but here we will learn next step of magento grid, we are going apply formulas on grid values, Sometime we need to show sum of two column that time we used renderer class of magento, which overrides your column value to your calculated values.

Also Checkout other tutorial of Magento,

Step 1: First thing we need to create our own column renderer class and method. We will Simply copy the magento core renderer class
/app/code/core/Mage/Adminhtml/Widget/Grid/Renderer/Action.php to your own module folder with a new name /demo_magento/app/code/local/Mage/Adminhtml/Block/Customer/Renderer/type.php.

Step 2: We will paste below code on above created file.

**  
 * @file                : Type.php                
 * @created by          : Parvez Alam  
 * @creation date       : nov 14, 2011                    
 * @code briefing       : this file is used for handling model class                  
 */  
 class Mage_Adminhtml_Block_Customer_Renderer_Parentid extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {  
    public function render(Varien_Object $row) {  
        $value = ”;  
        //print_r($row->getData('mem_plan_name'));die;  
        if ($row->getData('mem_plan_name') != ” && $row->getData('mem_parent_id') == 0) {  
            $value = '';  
        }elseif($row->getData('mem_plan_name') != ” && $row->getData('mem_parent_id') > 0)  
        {  
         $value = 'Secondary Member';  
        }  
         
        return $value;  
    }  

How To use Column Renderer in admin file :

We will modify our form control and add our renderer method to targeted column.

$this->addColumn('mem_plan_name', array(  
            'header'    =>  Mage::helper('customer')->__('Member Plan'),  
            'width'     =>  '100′,  
            'index'     =>  'mem_plan_name',  
            'default'   => '—-',  
            'renderer'  => 'Mage_Adminhtml_Block_Customer_Renderer_Parentid'  
        ));