2

I want to create select type for a grid column in magento admin panel.inside _prepareColumns() function

protected function _prepareColumns()
    {
        if (!$this->getCategory()->getProductsReadonly()) {
            $this->addColumn('in_category', array(
                'header_css_class' => 'a-center',
                'type'      => 'checkbox',
                'name'      => 'in_category',
                'values'    => $this->_getSelectedProducts(),
                'align'     => 'center',
                'index'     => 'entity_id'
            ));
        }
        $this->addColumn('entity_id', array(
            'header'    => Mage::helper('catalog')->__('ID'),
            'sortable'  => true,
            'width'     => '60',
            'index'     => 'entity_id'
        ));
        $this->addColumn('name', array(
            'header'    => Mage::helper('catalog')->__('Name'),
            'index'     => 'name'
        ));
        $this->addColumn('position', array(
            'header'    => Mage::helper('catalog')->__('Position'),
            'width'     => '1',
            'type'      => 'select',
            'index'     => 'position',
            'editable'  => !$this->getCategory()->getProductsReadonly()
            //'renderer'  => 'adminhtml/widget_grid_column_renderer_input'
        ));

        return parent::_prepareColumns();
    }

Magento uses addColumn() function to create grid column, I want to create a column with select type, but I don't know how to provide it with options

2

Try this for get dynamic dropdown of customer attibutes like customer_type .you also change attributes name or put static values.

 $this->addColumn('column_name', array(
        'header' => Mage::helper('customer')->__('Attribute label'),
        'align' => 'left',
        'width' => '100px',
        'index' => 'atribute_code',
        'type' => 'options',
        'options' => $this->_getAttributeOptions('atribute_code'),
    ));


  protected function _getAttributeOptions($attribute_code)
    {
        $attribute = Mage::getModel('eav/config')->getAttribute('customer', $attribute_code);
        $options = array();
        foreach( $attribute->getSource()->getAllOptions(false) as $option ) {
            $options[$option['value']] = $option['label'];
        }
        return $options;

    }
1

Try the following:

    $this->addColumn('your_column_name', array(
        'header'    => Mage::helper('catalog')->__('your attribute label'),
        'index'     => 'your_attribute_code',
        'type'      => 'options',
        'options'   => array('Option 1', 'Option 2', ....)
    ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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