Grid filter with custom renderer

I have a problem with a filter in my module in the admin grid.

My problem: The filter for columns with a custom renderer does not work.

public function _prepareColumns() { $this->addColumn('entity_id', array( 'header' => 'ID', 'index' => 'entity_id', 'width' => '30px' )); $this->addColumn('author', array( 'header' => 'Author', 'index' => 'author', 'renderer' => 'Test_Block_Adminhtml_Vj_Renderer_Author' )); 

renderer

 class Test_Block_Adminhtml_Vj_Renderer_Author extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { public function render(Varien_Object $row) { $value = $row->getData($this->getColumn()->getIndex()); $autor = Mage::getModel('test/test')->load($value); return ($author->getName() . ' ' . $author->getSurname()); } } 

The author in the grid shows, for example, "George W. Bush", but if I try to write a filter (for example, "Boo"), the filter will return a zero line.: - /

Any idea? thanks.

+6
source share
1 answer

This article may help ... http://www.atwix.com/magento/grid-filter-for-columns/

In your addColumn () call for the custom field, add something like ...

'filter_condition_callback' => array($this, '_myCustomFilter'),

Then add a filter method (changing "where ()" as needed).

 protected function _myCustomFilter($collection, $column) { if (!$value = $column->getFilter()->getValue()) { return $this; } $this->getCollection()->getSelect()->where( "my_field like ?" , "%$value%"); return $this; } 
+14
source

All Articles