Add custom column in admin Grid which will show radio/checkbox button. I know this is weird, but some people need this as a requirement. Here I will show you how you can have radio button or checkbox button that you can have directly in your grids.
For radio button,
$this->addColumn('some_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('adminhtml')->__('Some Header'),
'type' => 'radio',
'html_name' => 'items[]',
'align' => 'center',
'value' => array('1')
));
For checkbox button,
$this->addColumn('some_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('adminhtml')->__('Some Header'),
'type' => 'radio',
'field_name' => 'items[]',
'align' => 'center',
'values' => array('1','2')
));
Further, in Form.php you can add this below code to have by default behavior and onclick behaviour:
$fieldset->addField('some_id', 'checkbox', array(
'checked' => $this->getSomeId()==1 ? 'true' : 'false',
'onclick' => 'this.value = this.checked ? 1 : 0;'
));
Hope this helps some frustrated mind!
For radio button,
$this->addColumn('some_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('adminhtml')->__('Some Header'),
'type' => 'radio',
'html_name' => 'items[]',
'align' => 'center',
'value' => array('1')
));
For checkbox button,
$this->addColumn('some_id', array(
'header_css_class' => 'a-center',
'header' => Mage::helper('adminhtml')->__('Some Header'),
'type' => 'radio',
'field_name' => 'items[]',
'align' => 'center',
'values' => array('1','2')
));
Further, in Form.php you can add this below code to have by default behavior and onclick behaviour:
$fieldset->addField('some_id', 'checkbox', array(
'checked' => $this->getSomeId()==1 ? 'true' : 'false',
'onclick' => 'this.value = this.checked ? 1 : 0;'
));
Hope this helps some frustrated mind!
This comment has been removed by the author.
ReplyDelete