如何在客户网格中渲染/格式化自定义字段 - 后端Magento 1.6

Led*_*key 2 magento

任何人都可以帮我这个吗?我在magento后端管理页面中为客户网格添加了一些自定义字段,这些字段是选择字段,但我似乎无法找到在网格中显示"标签"的方法,而不是我试图找到的"值"此页面的渲染器,但没有运气...

它们在客户信息页面中显示正常(请参见屏幕截图)

客户网格Sreenshot

在此输入图像描述

我发现这篇文章非常有用,但不知道我需要写什么才能让标签内容显示出来?http://inchoo.net/ecommerce/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/

提前谢谢了

Mag*_*cho 5

您不需要任何渲染器来显示此类值.这是你应该做的:

$boyGirlOptions = array(
    array('value' => 1, 'label' => 'Boy'),
    array('value' => 2, 'label' => 'Girl'),
); // or you can fetch dynamically
$this->addColumn('boy_or_girl', array(
    'header'    => Mage::helper('your-module')->__('Boy or Girl'),
    'index'     => 'boy_or_girl',
    'type'      => 'options',
    'options'   => $boyGirlOptions,
    'align'     => 'left',
));

$sourceOptions = array(
    array('value' => 1, 'value' => 'Google'),
    array('value' => 2, 'value' => 'Yahoo'),
    //... 
); //or you can fetch dynamically
$this->addColumn('where_did', array(
    'header'    => Mage::helper('your-module')->__('Where Did?'),
    'index'     => 'where_did',
    'type'      => 'options',
    'options'   => $sourceOptions,
    'align'     => 'left',
));
Run Code Online (Sandbox Code Playgroud)

是的,您需要使用下拉类型选项,网格值将自动获取标签而不是值(id).
希望这可以帮助.