Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

how can i display my image in admin grid? 
 
hardik.kgn
Jr. Member
 
Total Posts:  11
Joined:  2011-01-04
 

$this->addColumn(’filename’,array(
‘header’=> Mage::helper(’test’)->__(’filename’),
‘type’ => ‘image’,
‘width’ => ‘50px’,
‘index’ => ‘image’,
));

I have use above code to display images in grid but its not work
Please help me to show images in admin grid

Thanks
Hardik

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

Hi
Add the following code in your Grid.php

$this->addColumn('filename', array(
            
'header'=>Mage::helper('imagegallery')->__('Gallery Image'),
            
'filter'=>false,
               
'index'=>'filename',
            
'renderer'  => 'imagegallery/adminhtml_grid_renderer_image',
            
'align' => 'center',
            
'width'     => '200px',
               
        ));

And Add the following code in your module app/code/local/MagePsycho/Imagegallery/Block/Adminhtml/Grid/Renderer/Image.php:

class MagePsycho_Imagegallery_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    
public function render(Varien_Object $row)
    
{
        
if($row->getFilename()==""){
            
return "";
        
}
        else{
            
//you can also use some resizer here...
            
return "<img src='".Mage::getBaseUrl("media").$row->getFilename()."' width='75' height='75'/>";
        
}
    }
}

Note: This is the code extracted from one of my existing module. You can modify the Namespace and Module Name.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hardik.kgn
Jr. Member
 
Total Posts:  11
Joined:  2011-01-04
 

Hi,
Its work

Thanks
Hardik

 
Magento Community Magento Community
Magento Community
Magento Community
 
kickerpen
Jr. Member
 
Total Posts:  5
Joined:  2011-05-04
 

thanks a lot
worked

 
Magento Community Magento Community
Magento Community
Magento Community
 
vishal_2811
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2011-04-17
 

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,
        ));
Did you noticed here escape, sortable and filter? smile

For me variables were
Mycomapname = ‘Turnkeye’
Mymodule = ‘Testimonial’
Tbl_Colname = ‘testimonial_img’
mycomapname = ‘turnkeye’
mymodule = ‘testimonial’

That’s it nothing else, now delete the cache and reload the page you should see the screen something like following.

Alternatively you can also try
http://www.krishnasunuwar.com.np/2009/07/ecommerce-software-magento-showing-image-in-grid/

Hope this helps someone in need.

Thanks.

Image Attachments
Screenshot.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
maria_atwix
Sr. Member
 
Avatar
Total Posts:  129
Joined:  2012-01-23
 

Hi, here you can find useful information how to insert images in the Magento admin product grid http://www.atwix.com/magento/thumbnail-images-admin-product-grid/
Hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nayan Baraiya
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2011-08-15
 

thanks a lot
its worked

 
Magento Community Magento Community
Magento Community
Magento Community
 
jess_17
Jr. Member
 
Total Posts:  1
Joined:  2013-10-06
 

Step 1:
First you need to copy the core block to local. Copy Grid.php from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php
Here you’ll find a method named _prepareColumns(), add the below code within this method

$this->addColumn(’product_image’, array(
‘header’ => Mage::helper(’catalog’)->__(’Image’),
‘align’ =>’left’,
‘index’ => ‘entity_id’,
‘width’ => ‘100px’,
‘renderer’ => ‘Mage_Adminhtml_Block_Catalog_Product_Renderer_Image’
));

Step 2:
Now create the renderer file named Image.php in the following path
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Renderer/Image.php
Here add the below code..

class Mage_Adminhtml_Block_Catalog_Product_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$_product = Mage::getModel(’catalog/product’)->load($row->getEntityId());
if($_product->getImage() != ‘no_selection’){
$image = “<img src=’”.Mage::helper(’catalog/image’)->init($_product, ‘image’)->resize(100).”’ title=‘“.$_product->getName().”’ />”;
}
return $image;
}
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
monkeydriver
Jr. Member
 
Total Posts:  1
Joined:  2010-09-11
 

I think I am having a brain fade on this today - but I am trying to use an external image extension and pulling these images into an admin grid panel.

I currently have this:

public function render(Varien_Object $row) {

$p = Mage::getModel(’catalog/product’)->load($row->getproduct_id());
$html = ‘<img src=”’ . Mage::getBaseUrl(’media’) . ‘catalog/product’ . $p->getsmall_image() . ‘“ width="50" height="50" alt=”’ . $p->getname() . ‘“ />’;
return $html;

and have used the below info from tzyganu below in the past:

<?php
$imageCollection = Mage::getModel('catalog/product')->load($_item['product_id']);
$i=0;
foreach ($imageCollection->getMediaGalleryImages() as $_image) {
if($i == 0) {
?>

<a href="#" onclick="Popup=window.open(’<?php echo $this->helper('catalog/image')->init($imageCollection, 'catalog/product', $_image->getFile())->resize(350); ?>’,’Popup’,’toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=500,height=500,left=430,top=23’); return false;” style="float:center; margin-right:10px">

<img src="<?php echo $this->helper('catalog/image')->init(Mage::getModel('catalog/product')->load($_item->getProductId()), 'small_image')->resize(75); ?>” width="75" height="75" alt="<?php echo $this->htmlEscape($_item->getName()) ?>” />

<!--alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>”
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>” />-->
</a>
<?php } $i++; }
?>

I have the image box appear but no actual thumbnail image appears - can anyone let me know what I am doing wrong ?? :-(

 
Magento Community Magento Community
Magento Community
Magento Community
 
pandurang_babar
Jr. Member
 
Total Posts:  2
Joined:  2013-07-21
 

Thanks @vishal_2811
It works for me.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top