I am creating a custom grid in an admin module. This grid represents a table almost column for column, however, I want to add a completely custom column with a bit of logic to this column. Here's my (simplified) code...
protected function _prepareCollection()
{
$collection = Mage::getModel('me/mymod')
->getCollection();
$this->setCollection($collection);
// I need to perform some logic here to 'inject' into the _prepareColumns()
$testString = Mage::app()->getRequest()->getParam('testString');
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('username', array(
'header' => Mage::helper('mymod')->__('Username'),
'index' => 'username',
));
// I want to get a value from 'prepareColumns() here
$this->addColumn('test_string', array(
'header' => Mage::helper('mymod')->__('Test String'),
'index' => 'testString',
));
return parent::_prepareColumns();
}
I know I can use a custom renderer here, but in my prepareColumns()
method, I set a mode based on the request - so would need to pass that custom $testString
through to the renderer instead - which seems even harder.
The easiest way I could thing was to just add a literal column to the collection call in prepareCollection()
as asked here...
Add custom 'select' statement to Collection Magento 1.9
But I don't think it's possible.
I know I could put some custom logic in _prepareColumns()
but it just seems messy - prepareCollection is obviously there to do exactly that.
Any ideas?