Format the column display info of Grid ---- Magento

When develop a E-Commerce site base on magento, you will find mostly all information you can 

get on the magento admin panel display as a Grid. Some situation we have to customize the displaying 

information of the column.

There are two solution can do that:

1.  Use the  " format "  attribute of  column.

2.  Use the  " renderer attribute of  column .


Such as : on the  Report->Shopping cart -> product in carts  list grid ----Magento admin. we want the name of the product display as a link we can click it to the product detail page.

 

First  Solution:

1.  Rewrite adminhtml/ report_shopcart_product_grid (refernce to  magento rewrite block ):

2.  Change the grid block class like this:

Replace:

$this ->addColumn( 'entity_id' array (

       'header'     =>Mage::helper( 'reports' )->__( 'ID' ),

       'width'      => '50px' ,

       'align'      => 'right' ,

       'index'      => 'entity_id'

));

$this ->addColumn( 'name' array (

       'header'   =>Mage::helper( 'reports' )->__( 'Product Name' ),

       'index'      => 'name'

));

 

With:

$this ->addColumn( 'entity_id' array (

       'header'     =>Mage::helper( 'reports' )->__( 'ID' ),

         'width'      => '50px' ,

        'align'      => 'right' ,

       'index'      => 'entity_id'

));

$this ->addColumn( 'name' array (

       'header'     =>Mage::helper( 'reports' )->__( 'Product Name' ),

       'index'      => 'name' ,

       'format'   => '<a href="/catalog/product/view/id/$entity_id" target="_blank">$name</a>'

));

 

 

Second Solution:

1.  Rewrite adminhtml/ report_shopcart_product_grid (refernce to  magento rewrite block ):

2.  Rewrite adminhtml/ report_grid_column_renderer_ link like this   

<?php

class   Red _Adminhtml_Block_Report_Grid_Column_Renderer_ Link   extends  

Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract

{

     public   function  render(Varien_Object  $row )

{

$id = $row ->getData( $this ->getColumn( 'entity_id' )->getIndex());          $value  =  $row ->getData( $this ->getColumn()->getIndex());;

Return   " <a   href="/catalog/product/view/id/ { $ id} " target="_blank">$ value </a> " ;

    }

}

 

 

3.  Change the grid block class like this:


Replace:

$this ->addColumn( 'entity_id' array (

       'header'     =>Mage::helper( 'reports' )->__( 'ID' ),

       'width'      => '50px' ,

       'align'      => 'right' ,

       'index'      => 'entity_id'

));

$this ->addColumn( 'name' array (

       'header'   =>Mage::helper( 'reports' )->__( 'Product Name' ),

       'index'      => 'name'

));

 

With:

$this ->addColumn( 'entity_id' array (

       'header'     =>Mage::helper( 'reports' )->__( 'ID' ),

         'width'      => '50px' ,

        'align'      => 'right' ,

       'index'      => 'entity_id'

));

$this ->addColumn( 'name' array (

       'header'     =>Mage::helper( 'reports' )->__( 'Product Name' ),

       'index'      => 'name' ,

'renderer' => 'adminhtml/report_grid_column_renderer_ link '//the block you change to deal with the data

));

 

NOTE: The first solution just can be used when you want to change the string to anthoer string type: such as adding htm, add other string.......If you want to make some operation with this column value, you need use the second one.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值