Mage / Adminhtml / Widget / Grid / Column / Renderer / Concat.php - 有人可以提供一个使用示例吗?例如,它可以用来代替:
$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',
));
答案 0 :(得分:13)
谢谢西蒙! addColumn渲染器在Mage_Adminhtml_Block_Widget_Grid_Column :: _ getRendererByType()中显示出来,所以没有必要手动添加它,尽管知道这个很酷。如果我不使用过滤器索引,我仍然会遇到问题,但我确实将代码清理干净了:
$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',
)
);
答案 1 :(得分:1)
我认为它应该像renderer
中的每个渲染器一样使用。要连接的列可以在index
中的数组中设置。我认为不可能像你想要的那样使用separators
。它在产品网格中进行了测试:
$this->addColumn('entity_id',
array(
'header'=> Mage::helper('catalog')->__('ID'),
'index' => array('entity_id','sku'),
'separator'=>'|',
'renderer' => 'adminhtml/widget_grid_column_renderer_concat',
));
答案 2 :(得分:1)
我们可以使用以下方法在Grid中合并两列。
$this->addColumn('name', array(
'header' =>Mage::helper('customreport')->__('Name'),
'sortable' =>true,
'index' =>array('firstname', 'lastname'),
'type' =>'concat',
'separator' =>' '
));