Magento – Add custom Checkbox Columns to Custom Form Grid in Admin

adminformsgridmagento-1.9

I have added a custom Tab grid to Form Section in my custom module, now I need to add some custom Column of checkbox type to my custom grid, which I added as per snapshot –

but all the custom Checkbox are coming disabled, I need these checkboxes enabled.

enter image description here

Best Answer

Please consider the following things.

For example:

if your attribute is banner_gral Then in your controller saveAction() when saving the checkbox data do

$banner_gral = isset($your_form_Data['banner_gral']) ? 1 : 0;

For Grid and Form Page

In your controller you should have Mage::register(...)->getData() or Mage::register(...)

public function editAction()
     ....
     Mage::register('example_data', $model);

On your form _prepareForm()

$model = Mage::registry('example_data'); // NOTE registry('example_data'); NOT registry('example_data')->getData();

$fieldset->addField('entire_range', 'checkbox', array(
      ....
      'checked'    => $model->getBannerGral()==1 ? 'true' : 'false',
       ......
))

On your grid _prepareColumns()

$this->addColumn('banner_gral', array(
    ....
    'type'     => 'checkbox',
    'index'    => 'banner_gral',
    'values'   => array(1,2),
    'field_name' => 'checkbox_name',
    ....
));
Related Topic