2
votes

can anybody help me with this ? I have added some custom fields to the customer grid in the magento backend admin page which are select fields , but I cant seem to find a way of showing the "label" in the grid as opposed to the "value" I have tried to find the renderer for this page but have had no luck...

They render ok in the customer information page (please see screenshots)

Customer Grid Sreenshot

enter image description here

I have found this post which is very helpful but do not know what i need to write to get the label content to dispay ? http://inchoo.net/ecommerce/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/

Many thanks in advance

2

2 Answers

5
votes

You don't need any renderer for displaying such values. Here is what you should do:

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

Yes, you need to use dropdown type options and grid values will automatically get the label instead of value(id).
Hope this helps.

1
votes

You should add options parameter to your $this->addColumn() statement:

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