Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tobias-forkel/c5f34f25f2e6fc60822d to your computer and use it in GitHub Desktop.
Save tobias-forkel/c5f34f25f2e6fc60822d to your computer and use it in GitHub Desktop.
Use a block in your grid column renderer
<?php
/**
* Namespace ModuleName
*
* @category Namespace
* @package Namespace_ModuleName
* @copyright Copyright (c) 2015 Tobias Forkel (http://www.tobiasforkel.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Namespace_ModuleName_Block_Adminhtml_Item_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
/**
* Prepare grid columns
*
* @return Namespace_ModuleName_Block_Adminhtml_Item_Grid
*/
protected function _prepareColumns()
{
$this->addColumn('is_active',
array(
'header' => $this->__('Active'),
'index' => 'is_active',
'renderer' => 'Namespace_ModuleName_Block_Adminhtml_Item_Renderer_IsActive'
)
);
}
}
<?php
/**
* Namespace ModuleName
*
* @category Namespace
* @package Namespace_ModuleName
* @copyright Copyright (c) 2015 Tobias Forkel (http://www.tobiasforkel.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Namespace_ModuleName_Block_Adminhtml_Item_Renderer_IsActive extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
/**
* Render
*
* @param Varien_Object $row
*
* @return string
*/
public function render(Varien_Object $row)
{
return $this->getLayout()->createBlock('namespace/modulename/adminhtml_item_cell_isActive')->setRow($row)->toHtml();
}
}
<?php
/**
* Namespace ModuleName
*
* @category Namespace
* @package Namespace_ModuleName
* @copyright Copyright (c) 2015 Tobias Forkel (http://www.tobiasforkel.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Namespace_ModuleName_Block_Adminhtml_Entity_Cell_IsActive extends Mage_Adminhtml_Block_Widget_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('namespace/modulename/adminhtml/item/cell/isactive.phtml');
}
}
<?php $row = $this->getRow(); ?>
<strong>The content for your grid cell. Do something with $row.</strong>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment