Skip to main content
deleted 1 character in body
Source Link
7ochem
  • 7.6k
  • 14
  • 52
  • 80

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'modulename/adminhtml_modulename_renderer_image', //get the image HTML code class name in render class should be written in  small lattercaps
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's BLock>Adminhtml>ModuleName>Renderer>Image.phpBlock/Adminhtml/ModuleName/Renderer/Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'modulename/adminhtml_modulename_renderer_image', //get the image HTML code class name in render class should be written in  small latter
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's BLock>Adminhtml>ModuleName>Renderer>Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'modulename/adminhtml_modulename_renderer_image', //get the image HTML code class name in render class should be written in small caps
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's Block/Adminhtml/ModuleName/Renderer/Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'ModuleName'modulename/adminhtml_ModuleName_renderer_image'adminhtml_modulename_renderer_image', //get the image HTML code class name in render class should be written in  small latter
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's block/Adminhtml/ModuleName/Renderer/ImageBLock>Adminhtml>ModuleName>Renderer>Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'ModuleName/adminhtml_ModuleName_renderer_image', //get the image HTML code
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's block/Adminhtml/ModuleName/Renderer/Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'modulename/adminhtml_modulename_renderer_image', //get the image HTML code class name in render class should be written in  small latter
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's BLock>Adminhtml>ModuleName>Renderer>Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>
Source Link

To display image in custom admin grid you need to add a column in grid.php with following code:

$this->addColumn('Database_Field_Name', array(
          'header'    => Mage::helper('ModuleName')->__('Image'),
          'align'     =>'left',
          'type'      => 'image',
          'index'     => 'Database_Field_Name',
          'renderer' => 'ModuleName/adminhtml_ModuleName_renderer_image', //get the image HTML code
          'filter'    => false,
          'sortable'  => false,
));

After that you need to create following image renderer file on module's block/Adminhtml/ModuleName/Renderer/Image.php location

<?php
class NameSpace_ModuleName_Block_Adminhtml_ModuleName_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   public function render(Varien_Object $row)   {
        $html = '<img id="' . $this->getColumn()->getId() . '" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= '/>';
        return $html;
    }
}
?>