I'm working with custom module for the magento backend, in this filter not working when using filter calback! Can anyone suggest me? Thanks!
I have tried some codes like this,
Grid.php
protected function _prepareCollection()
{
$collection = Mage::getModel('listings/listings')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn("item_id", array(
"header" => Mage::helper("linkmanagement")->__("ID"),
"align" => "center",
"type" => "number",
"index" => "item_id",
));
$this->addColumn("title", array(
"header" => Mage::helper("linkmanagement")->__("Title"),
"index" => "title"
));
$this->addColumn("cat_ids", array(
"header" => Mage::helper("linkmanagement")->__("Cat ID"),
"align" => "center",
"index" => "cat_ids",
"renderer" => 'Sathish_Linkmanagement_Block_Adminhtml_Linkmanagement_Renderer_Categories',
'filter_condition_callback' => array($this, '_categoriesFilter')
));
$this->addColumn("url_key", array(
"header" => Mage::helper("linkmanagement")->__("URL"),
"index" => "url_key",
"width" => "200px",
));
$this->addColumn('status',
array(
'header' => Mage::helper('linkmanagement')->__('Status'),
'index' => 'status',
'type' => 'options',
'options' => array('1' => Mage::helper('linkmanagement')->__('Active'),
'0' => Mage::helper('linkmanagement')->__('Inactive')),
)
);
return parent::_prepareColumns();
}
callback function
protected function _categoriesFilter($collection, $column)
{
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$this->getCollection()->getSelect()->where(
"cat_ids ?"
, "%$value%");
return $this;
}
Categories.php
class Sathish_Linkmanagement_Block_Adminhtml_Linkmanagement_Renderer_Categories extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$value = $row->getData($this->getColumn()->getIndex());
// $value = 38,92
$value = explode(',',$value);
$collection = Mage::getModel("categories/categories")->getCollection()->addFieldToFilter('category_id',$value)->getData();
foreach($collection as $col){
$result[] = $col['title'];
}
$result = implode(',', $result);// $result = schools,colleges
return $result;
}
}
Note: Renderer working fine., only filter callback function is not working!!!
I checked your example with my own renderer and tried to check your callback.
Replace in your callback method
with
Here are my pieces of advice:
Magento filter assumes not 100% similarity. I mean that if you want to apply filter you should use construction:
I still don't understand answer on question below:
Put
Mage::log('blabla', false, 'grid.log', true);
at the beginning of the callback method. Then check this log file. If it's not empty - your method calls successfully.If your method calls - try to
before and after filter applying. And try to run these queries in phpmyadmin. Check the result
Try to apply these changes inside Mage_Adminhtml_Block_Sales_Order_Grid class
Here what I did:
....
...