1

How do I create a value then add it to the _prepareColumns() function?

I would like to work out a value then add it to a row that is coming form the database.

  • Can you be more specific? Do you mean that you want to take a value from field X off the table, manipulate it, and render it into column C? – Rick Buczynski Nov 21 '14 at 14:33
  • Yes that is what I want to do – daktau Nov 21 '14 at 15:14
  • ok - in that case, see my answer below – Rick Buczynski Nov 21 '14 at 15:23
2

In _prepareColumns for your desired "dynamic column," try this:

$this->addColumn('my_column', array(
    'header'    => Mage::helper('module')->__('My Column'),
    'type'      => 'text',
    'renderer'  => 'module/adminhtml_column_renderer_mycolumn'
));

Notice the renderer element, which points to an admin block (a column renderer). Construct your renderer like this:

class Namespace_Module_Block_Adminhtml_Column_Renderer_Mycolumn 
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
{

    public function render(Varien_Object $row) 
    {
        // $row is your model
        return $row->getEnabled() ? '<strong>ENABLED</strong>' : '<em>DISABLED</em>';
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.