magento - 使用自定义渲染器过滤网格

标签 magento magento-1.7

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

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

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”)过滤器返回零行。 :-/

任何的想法?
谢谢。

最佳答案

这篇文章可能会有所帮助... 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;
}

关于magento - 使用自定义渲染器过滤网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14149409/

相关文章:

Magento:如何从观察者管理中的现有表单获取magento字段集

magento - 将产品添加到购物车时出错 magentosoap

Magento - 上传 HTTP 错误?

php - Magento 获取购物车单件商品价格,包括。税

Magento - 如何在查看 phtml 文件中向 friend 表单显示电子邮件

testing - Paypal 现场测试

php - 跟踪 Google Analytics 目标中的表单输入

jquery - 玛根托 : frontend form validation multiple input radio

magento的css路径

c# - 我如何(从 SalesOrderEntity)检索送货地址?