1

I am trying to display custom dropdown in admin grid of Magento. i have added in database income_source attribute as a enum. with values 'C' 'I' and after saving this I want to display it on admin panel grid with label 'customer''incentives' .

I have added this code in protected function _prepareColumns() function

$attribute = Mage::getModel('contactus/contactus')->getAttribute('wel_contactus', 'income_sourcer');
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option )     {
   $options[$option['C']] = $option['Customer'];
   $options[$option['I']] = $option['Incentives'];
}
$this->addColumn('income_source',
array(
    'header'=> Mage::helper('contactus')->__('Income Source'),
    'width' => '80px',
    'index' => 'income_source',
    'type'  => 'options',
    'options' => $options,
)); 

But it showing error

Fatal error: Call to a member function getSource() on a non-object. thanks in advance.

5
  • fatal error is because you are not getting proper data in $attribute
    – Piyush
    Jan 5, 2017 at 11:17
  • so how to get data in $attrubute
    – Neeya
    Jan 5, 2017 at 11:18
  • in which table you have saved your data?
    – Piyush
    Jan 5, 2017 at 11:20
  • i have save this data in custom module with custom table name as 'contactus'
    – Neeya
    Jan 5, 2017 at 11:21
  • can i add all this code in grid.php
    – Neeya
    Jan 5, 2017 at 11:27

1 Answer 1

1

Try Like this-

$collections = Mage::getModel('contactus/contactus')->getCollection();
$options = array();
$i = 0;
foreach ($collections as $key => $value) {
    $i++;
    $options[$value->getYourTableColumn()] = $value['your_table_column'];
}

$this->addColumn('income_source',
array(
    'header'=> Mage::helper('contactus')->__('Income Source'),
    'width' => '80px',
    'index' => 'income_source',
    'type'  => 'options',
    'options' => $options,
)); 

Or If you want the option to be fixed then you can do like this-

$this->addColumn('income_source',
array(
    'header'=> Mage::helper('contactus')->__('Income Source'),
    'width' => '80px',
    'index' => 'income_source',
    'type'  => 'options',
    'options' => array(
                'C' => 'Customer',
                'I' => 'Incentives',
            ),
)); 
0

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.