0

I want to add some column as a drop drown with some values (not in grid)but I can't get Them , I don't know why !

enter image description here

Test 1:

$this->addColumn('somme', array(
            'label'   => Mage::helper('module')->__('Somme'),
            'style'   => 'width:100px',
            'type'    => 'options',
            'options'   => array(0 => $this->__('Value1'), 1 => $this->__('Value2')),
            'sortable'  => false,
        ));

Test 2:

$this->addColumn('somme', array(
            'label'   => Mage::helper('module')->__('Somme'),
            'style'   => 'width:100px',
            'type'    => 'options',
            'renderer' => 'Module_ModuleName_Block_Config_Adminhtml_Renderer_Dropdown',
        ));

Module_ModuleName_Block_Adminhtml_Renderer_Dropdown

class Module_ModuleName_Block_Config_Adminhtml_Renderer_Dropdown extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
    public function render(Varien_Object $row) {
        $html = '<select>';
        $html .= '<option value="0">Value1</option>';
        $html .= '<option value="1">Value2</option>';
        $html .= '</select>';
        return $html;
    }
}

1 Answer 1

2

I found the solution :

Module/ModuleName/Block/Config/Somename.php

<?php
class Module_ModuleName_Config_Somename extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
{
    protected $_itemRenderer;

    public function _prepareToRender()
    {
        $this->addColumn('somme', array(
            'label'   => Mage::helper('module')->__('Somme'),
            'style'   => 'width:100px',
            'renderer' => $this->_getRenderer(),
        ));
    }
    protected function _getRenderer()
    {
        $this->_itemRenderer = $this->getLayout()->createBlock(
            'module_moduleName/config_adminhtml_form_field_conditions', '',
                array('is_render_to_js_template' => true)
        );
        return $this->_itemRenderer;
    }
}

Module/ModuleName/Block/Config/Adminhtml/Form/Field/Conditions.php

<?php

class Module_ModuleName_Block_Config_Adminhtml_Form_Field_Conditions extends Mage_Core_Block_Html_Select {

    public function _toHtml()
    {
        $html = '<select>';
        $html .= '<option value="First">First value</option>';
        $html .= '<option value="Second">Second value</option>';
        $html .= '</select>';
        return $html;
    }

    public function setInputName($value)
    {
        return $this->setName($value);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.