Magento: Add radio/checkbox in custom column in Admin Grid

Standard

Magento grids are very useful for displaying/filtering and sorting data. Their flexibility is endless, you can customize them in any way. One may want to add a new radio button or checkbox column for rapid marking.

Here is how you can add custom checkbox or radio button column in Magento admin grid.

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')
));

Checkbox:

$this->addColumn('some_id', array(
    'header_css_class' => 'a-center',
    'header' => Mage::helper('configurator')->__('Some Header'),
    'index' => 'some_id',
    'type' => 'checkbox',
    '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(
    'label' => Mage::helper('magentostudy_news')->__('Featured'),
    'name' => 'featured',
    'value' => 1,
    'checked' => ($model->getFeatured() == 1) ? 'true' : '',
    'onclick' => 'this.value = this.checked ? 1 : 0;',
    'disabled' => false,
    'readonly' => false,
));
Advertisements

2 thoughts on “Magento: Add radio/checkbox in custom column in Admin Grid

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: