Search code examples
magentogridmagento-1.7concatenationadminhtml

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',
));

Solution

  • 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',
        )
    );