Magento – how to create option for grid column select in magento

magento-1.7

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

Best Answer

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;

    }
Related Topic