Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the 'concat' type in the addColumn() method when building a grid?

Mage/Adminhtml/Widget/Grid/Column/Renderer/Concat.php -- can someone please provide an example of its usage? For instance, can it be used in place of:

$this->addColumn('order_item', array(
  'header'=> $this->__('Order # (Item #)'),
  'sortable'=> true,
  'index'=> 'order_item',
  'filter_index'=> "CONCAT(orders.increment_id, ' (', main_table.item_id, ')')",
  'width'=> '140px',
));
like image 764
monkeygod Avatar asked Jun 07 '13 16:06

monkeygod


3 Answers

Thanks Simon! The addColumn renderers are cased out in Mage_Adminhtml_Block_Widget_Grid_Column::_getRendererByType() so it is not necessary to manually add it although that is very cool to know. I still had issues if I left off the filter index, but I did clean up the code to this:

$this->addColumn('order_item', 
    array(
        'header'       => $this->__('Order # -- Item #'),
        'sortable'     => true,
        'index'        => array('increment_id', 'item_id'),
        'type'         => 'concat',
        'separator'    => ' -- ',
        'filter_index' => "CONCAT(orders.increment_id, ' -- ', main_table.item_id)",
        'width'        => '140px',
    )
);
like image 122
monkeygod Avatar answered Nov 14 '22 14:11

monkeygod


I think it should be used like every renderer in renderer. The columns to be concatenated can be set in an array in index. I think it's not possible to use separators like you want to. It tested in product grid:

  $this->addColumn('entity_id',
        array(
            'header'=> Mage::helper('catalog')->__('ID'),
            'index' => array('entity_id','sku'),
            'separator'=>'|',
            'renderer' => 'adminhtml/widget_grid_column_renderer_concat',
    ));
like image 39
Simon H Avatar answered Nov 14 '22 15:11

Simon H


We can merge two columns in Grid using below method.

$this->addColumn('name', array(
            'header'    =>Mage::helper('customreport')->__('Name'),
            'sortable'  =>true,
            'index'     =>array('firstname', 'lastname'),
            'type'      =>'concat',
            'separator' =>' '
        ));
like image 1
Digisha Avatar answered Nov 14 '22 14:11

Digisha