【发布时间】:2015-03-08 21:41:43
【问题描述】:
我的管理网格模块中的过滤器有问题。 我还在自定义表中使用了“order_item_id”字段,并使用渲染器根据“(sales/order_item)”获取产品名称。 我也使用“ 'filter_condition_callback' => array($this, '_productFilter') ”但它不能工作 我的问题是:无法过滤自定义渲染器不起作用的列。 当我在列中搜索产品名称时,它返回零记录。 我的代码有什么问题?
public function _prepareColumns()
{
$this->addColumn('entity_id', array(
'header' => Mage::helper('adminhtml')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'entity_id',
));
$this->addColumn('order_item_id', array(
'header' => Mage::helper('adminhtml')->__('Product Name'),
'align' =>'right',
'index' => 'order_item_id',
'renderer' => 'Test_Module1_Block_Adminhtml_Renderer_Product',
'filter_condition_callback' => array($this, '_productFilter'),
));
return parent::_prepareColumns();
}
protected function _productFilter($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$this->getCollection()->getSelect()->where(
"order_item_id like ?
"
, "%$value%");
return $this;
}
我的渲染器是
class Test_Module1_Block_Adminhtml_Renderer_Product extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$order = Mage::getModel('sales/order_item')->load($row->getData('order_item_id'));
return $order->getName();
}
}
【问题讨论】:
标签: magento grid admin renderer