使用自定义渲染器在网格中过滤 [英] Filter in grid with custom renderer
问题描述
我在管理网格中的模块中的过滤器有问题.
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'
));
渲染器是
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'),则过滤器返回零行. :-/
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.
推荐答案
本文可能会帮助您... http://www.atwix.com/magento/grid-filter-for-columns/
This article may help... http://www.atwix.com/magento/grid-filter-for-columns/
在您对自定义字段的addColumn()调用中,添加类似...
On your addColumn() call for the custom field, add something like...
'filter_condition_callback' => array($this, '_myCustomFilter'),
然后添加过滤器方法(根据需要更改"where()")...
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;
}
这篇关于使用自定义渲染器在网格中过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!