Monday, 19 May 2014

way to display a thumbnail image in the admin grid view?

Step 1
======================================
Create Directories (if NOT there)
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/

Step 2
======================================
Create a file named “Image.php” at the following location
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/


 Step 3
======================================
Paste the following code into “Image.php” created above


class <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    
public function render(Varien_Object $row)
    
{
        
if($row->getData($this->getColumn()->getIndex())==""){
            
return "";
        
}
        else{
            $html 
'<img ';
            
$html .= 'id="' $this->getColumn()->getId() . '" ';
            
$html .= 'width="45" ';
            
$html .= 'height="35" ';
            
$html .= 'src="' Mage::getBaseUrl("media") . $row->getData($this->getColumn()->getIndex()) . '"';
            
$html .= 'class="grid-image ' $this->getColumn()->getInlineCss() . '"/>';
          
            return 
$html;
        
}
    }
}



 
Hi All,
You do not need to overwrite any thing at all, just follow these simple steps instead
Step 1
======================================
Create Directories (if NOT there)
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/
Step 2
======================================
Create a file named “Image.php” at the following location
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/
Step 3
======================================
Paste the following code into “Image.php” created above

class <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    
public function render(Varien_Object $row)
    
{
        
if($row->getData($this->getColumn()->getIndex())==""){
            
return "";
        
}
        else{
            $html 
'<img ';
            
$html .= 'id="' $this->getColumn()->getId() . '" ';
            
$html .= 'width="45" ';
            
$html .= 'height="35" ';
            
$html .= 'src="' Mage::getBaseUrl("media") . $row->getData($this->getColumn()->getIndex()) . '"';
            
$html .= 'class="grid-image ' $this->getColumn()->getInlineCss() . '"/>';
          
            return 
$html;
        
}
    }
}

Step 4
======================================
Open app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/<Mymodule>/Grid.php and paste the following code into the function protected function _prepareColumns() some where

$this->addColumn('<Tbl_Colname>', array(
            
'header'    => Mage::helper('<mycomapname>_<mymodule>')->__('Image'),
            
'align'     => 'left',
            
'width'     => '100px',
            
'index'     => '<Tbl_Colname>',
            
'type'      => 'image',
            
'escape'    => true,
            
'sortable'  => false,
            
'filter'    => false,
            
'renderer'  => new <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image,
        ));



===================================================================






No comments:

Post a Comment