2

i have a custom admin module will print some data

$this->addColumn('product_old_values', array(
    'header'    => Mage::helper('adminlog')->__('product_old_values'),
    'align'     =>'left',
    'width'     => '20%',
    'index'     => 'product_old_values',
)); 

since product_old_values is a serialized array (a long string), how can i run unserialize(product_old_values) before displaying into a grid?

1 Answer 1

2

render the column by below code

$this->addColumn('product_old_values', array(
    'header'    => Mage::helper('adminlog')->__('product_old_values'),
    'align'     =>'left',
    'renderer'  => 'Namespace_Modulename_Block_Adminhtml_Gridrender',
    'width'     => '20%',
    'index'     => 'product_old_values',
)); 

FOR RENDERING

class Namespace_Modulename_Block_Adminhtml_Gridrender extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
    {

        public function render(Varien_Object $row)
        {
         }
    }

for doing in grid class

 $this->addColumn('product_old_values', array(
        'header'    => Mage::helper('adminlog')->__('product_old_values'),
        'align'     =>'left',            
        'width'     => '20%',
        'index'     => 'product_old_values',
       'frame_callback' => array($this, 'callback_image')

    ));



public function callback_image($value)
 {
   //write your code
 }
7
  • is it a must to open another class? can i do it in grid class?
    – hkguile
    Commented May 6, 2015 at 1:55
  • you can do it with 'frame_callback' => array($this, 'callback_image') public function callback_image($value) { $width = 20; $height = 20; return "<img src='".Mage::getBaseUrl('media').$value."' width=".$width." height=".$height."/>"; } i used it for image Commented May 6, 2015 at 4:51
  • i update the answer.. Commented May 6, 2015 at 4:58
  • @QaisarSatti can we return custom HTML in callback_image() method ? Commented May 1, 2019 at 6:00
  • @dhavalsolanki yes Commented May 1, 2019 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.