Reading list Switch to dark mode

    Add Images In Grid

    Updated 11 October 2012

    In your custom module if you want to add images ,and also want to show it in grid.

    Then follow these easy steps .

    1. Make this directory structure in your custom module like :

    your_namespace/your_module_name/Block/Adminhtml/Template/Grid/Renderer

    2. Make file “Image.php” inside this directory and put code like this

    Searching for an experienced
    Magento Company ?
    Find out More
    class Namespace_Modulename_Block_Adminhtml_Template_Grid_Renderer_Image
    
    	extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action {
    
    	public function render(Varien_Object $row)
        {
            return $this->_getValue($row);
        }
    
    	public function _getValue(Varien_Object $row)
        {
            if ($getter = $this->getColumn()->getGetter()) {
                $val = $row->$getter();
            }
            $val = $row->getData($this->getColumn()->getIndex());
            $val = str_replace("no_selection", "", $val);
            $url = Mage::getBaseUrl('media') . DS . $val;
    
            $out ='<center><a href="'.$_url.'" target="_blank" id="imageurl">';
            $out .= "<img src=". $url ." width='60px' ";
            $out .=" />";
            $out .= '</a></center>';
    
            return $out;
    
        }
    }

    3. After That In your module “grid.php” add these line of code inside _preparecolumns () function

    $this->addColumn('image', array(  
        'header'    => Mage::helper('your_module_name')->__('Image'),  
        'align'     =>'center',  
        'width'     => '50px',  
        'index'     => 'image',
        'renderer' => 'your_module_name/adminhtml_template_grid_renderer_image',  
    ));

    4. Save and have fun.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home