How do I dynamically set a radio button on a custom grid?
so far I have tried: (each attempt has had both value and values)
'value' => array('checked'), //not based on db value but to see if it worked
'value' => $this->getdata('is_default') // var_dump shows it is null
'value' => $this->getIdFieldName('id_default')
none checked the button below is my code if that helps
class [classname] extends Mage_Adminhtml_Block_Widget_Grid
protected function _prepareColumns()
{
$this->addColumn('is_default', array(
'header' => $this->__('Default'),
'filter' => false,
'type' => 'radio',
'index' => 'is_default',
));
return parent::_prepareColumns();
}
EDIT
After further investigation into this issue I have found this class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Radio
and reading the code I believe that it is possible to set the button as checked, am I right? or have I read the code wrong? or am I looking in the wrong place?
/**
* Renders grid column
*
* @param Varien_Object $row
* @return string
*/
public function render(Varien_Object $row)
{
$values = $this->getColumn()->getValues();
$value = $row->getData($this->getColumn()->getIndex());
if (is_array($values)) {
$checked = in_array($value, $values) ? ' checked="checked"' : '';
} else {
$checked = ($value === $this->getColumn()->getValue()) ? ' checked="checked"' : '';
}
$html = '<input type="radio" name="' . $this->getColumn()->getHtmlName() . '" ';
$html .= 'value="' . $row->getId() . '" class="radio"' . $checked . '/>';
return $html;
}
Mage_Adminhtml_Block_Widget_Grid