【问题标题】:How do I render/format custom fields in the Customer Grid - backend Magento 1.6如何在客户网格中呈现/格式化自定义字段 - 后端 Magento 1.6
【发布时间】:2012-01-23 09:59:05
【问题描述】:

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

他们在客户信息页面中呈现正常(请看截图)

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

非常感谢提前

【问题讨论】:

    标签: magento


    【解决方案1】:

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

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

    是的,您需要使用下拉类型选项,并且网格值将自动获取标签而不是 value(id)。
    希望这会有所帮助。

    【讨论】:

    • 非常感谢这个出色的答案,现在已经整理好了!再次感谢
    【解决方案2】:

    您应该将options 参数添加到您的$this->addColumn() 语句中:

        $this->addColumn('column_name', array(
            ...
            'options' => array('id1' => 'label1', 'id2' => 'label2', ...)
        ));
    

    【讨论】:

    • 谢谢,我已将此添加到我的 statemnet 'options' => array('1'=> 'Boy','2'=> 'Girl'),
    • 我已将此添加到我的语句 'options' => array('1'=> 'Boy','2'=> 'Girl'), 1 - 2 是值,但仍然如此不在网格中呈现任何想法?谢谢
    • 您错过了'type' => 'options',,有关更多信息,请参阅上面的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多