我在管理网格的模块中的过滤器有问题。
我的问题是:
过滤自定义渲染器不起作用的列。
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/