I have a problem with filter in my module in admin grid.
My problem is: Filter for columns with custom renderer not working.
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 is
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());
    }
 }
Author in grid is showing fine for example 'George Bush', but if i try write to filter (for example 'Bu') filter return zero row. :-/
Any idea? Thx.
This article may help... http://www.atwix.com/magento/grid-filter-for-columns/
On your addColumn() call for the custom field, add something like...
'filter_condition_callback' => array($this, '_myCustomFilter'),
Then add the filter method (changing the "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;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With