6

我在管理网格的模块中的过滤器有问题。

我的问题是:使用自定义渲染器过滤列不起作用。

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'
        ));

渲染器是

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());
    }
 }

网格中的作者显示良好,例如“George Bush”,但如果我尝试写入过滤器(例如“Bu”)过滤器返回零行。:-/

任何想法?谢谢。

4

1 回答 1

15

这篇文章可能会有所帮助...... http://www.atwix.com/magento/grid-filter-for-columns/

在自定义字段的 addColumn() 调用中,添加类似...

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

然后添加过滤方法(根据需要更改“where()”)...

protected function _myCustomFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $this->getCollection()->getSelect()->where(
        "my_field like ?"
    , "%$value%");


    return $this;
}
于 2013-05-16T15:14:40.623 回答