0

I'm adding a column like so in _prepareColumns() method of a class that extends Mage_Adminhtml_Block_Widget_Grid:

$this->addColumn('status', array(
    'header' => $this->helper->__('Status'),
    'width'  => '20px',
    'renderer' => 'namespace_modulename/adminhtml_renderer_status'
));

It doesn't have an index and the values for this column are being shown properly in the grid but I am not able to filter because filtering needs a column in select statement to exist.

How can I filter a custom column that its value is returned from a renderer and could be anything?

0

I think you will have to use the 'filter_condition_callback' key. You should start by searching for 'filter_condition_callback' occurences in the core code and you will find some example.

For example, in app/code/core/Mage/Adminhtml/Block/Cms/Page/Grid.php.

Briefly, you have to write something like


'filter_condition_callback'=> array($this, '_filterWhatYouWantCondition')

and create a protected function _filterWhatYouWantCondition

  • filter_condition_callback filters the collection. But I don't have them in collection. – revo Jan 16 at 17:37
  • Well, a filter on a grid will be the result of a collection that has been filtered. As you are in the Mage_Adminhtml_Block_Widget_Grid block, you necessarily have a collection that you can get with $this->getCollection(). I guess you will have to find a way to filter this collection using the value returned by your renderer. – Julien Loizelet Jan 16 at 17:54
  • The problem is I'm using some renderers that return things that don't relate to current collection. They receive $row which is an instance of Mage_Sales_Model_Order_Item and return something that isn't in collection. So I can't use collection to filter the results. – revo Jan 16 at 17:57
  • Well, maybe you could modify the collection (in the _prepareCollection method for example) in order to put your "unrelated infos" in it. And then, you will be able to filter this collection depending on this "unrelated infos". It sounds tricky but I have no better idea. – Julien Loizelet Jan 16 at 18:02
  • May you please show an example? – revo Jan 16 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.