1
votes

Does anyone know how to add a field containing an input type text element or a dropdown element to a magento backend product list grid? I managed to add a new column to my custom module backend product listing grid like this:

$this->addColumn('blabla', array(
        'header'  => Mage::helper('customer')->__('On Hold?'),
        'width'   => '120',
        'index'   => 'bla',
        'type'    => 'options',
        'options' => array('1' => 'Yes', '0' => 'No')
));

but this command only adds the dropdown to my grid header, while i need the dropdown to appear in the left side of every product listed on that grid (just like the checkbox appears when you go for instance in backend on a product edit page and you select related products, or upsell products)

3

3 Answers

0
votes

Simple and fast solution as tip for next research - rewrite Mage_Adminhtml_Block_Catalog_Product_Grid, function _prepareColumns. Example you will create your block Module_Name_Block_Sample:

class Module_Name_Block_Sample extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    protected function _prepareColumns()
    {
        $this->addColumn('blabla', array(
            'header' => Mage::helper('customer')->__('On Hold?'),
            'width' => '120',
            'index' => 'bla',
            'type' => 'options',
            'options' => array('1' => 'Yes', '0' => 'No')
        ));

        return parent::_prepareColumns();
    }
}

You will get it as first field. And it may need rewrite _prepareCollection.

But it may be not better solution, I know.

0
votes

What you need is a custom renderer, where you can display any HTML you want. Something like this:

$this->addColumn('blabla', array(
    'header'  => Mage::helper('customer')->__('On Hold?'),
    'width'   => '120',
    'index'   => 'bla',
    'renderer' => 'module/sample_grid_renderer'
));

And then you create your renderer class, where you create HTML you need:

class Module_Name_Block_Sample_Grid_Renderer 
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $html = '<select name="row'.$row->getId().'"></select>';
        return $html;
    } 
}
0
votes
  $country = $fieldset->addField('country', 'select', array(
  'name'  => 'country',
  'label'     => 'Country',
  'values'    => Mage::getModel('adminhtml/system_config_source_country') ->toOptionArray()
  ));

Try it! Have a nice day. Thank you.