3

If I try to filter a field in the existing table works, but a field generated by max () does not work, even renaming, display the error getBackend().

Examples:

observer

$collection->getSelect()->columns(array('last_order' => 
            new Zend_Db_Expr ("(SELECT MAX(created_at) FROM " . 
            $collection->getTable('sales/order') . " WHERE customer_id = e.entity_id)")));

grid - _prepareCollection()

$this->getCollection()->addFieldToFilter('last_order', 1);

I was wondering how can I make this filter work with my select

  • Define 'does not work'. Can you also expand on what it is you are trying to do? – Jonathan Hussey Nov 17 '14 at 11:58
  • I am creating new fields in the grid, however when the field is not native of table, the filter of error getBackend() if max(), min(), sum() etc, even retitle – Dexxtz Nov 17 '14 at 12:03
  • Any particular reason you are using columns(), a join() is the normal way to include data from other tables. – Jonathan Hussey Nov 17 '14 at 12:47
  • I researched several examples and what worked was with columns (), nothing in particular. @JonathanHussey – Dexxtz Nov 17 '14 at 12:57
5

Here is an answer I gave ages ago on stackoverflow which deals with exactly that issue.

https://stackoverflow.com/a/9531624/485589

The gist of it is that when you add a column with a computed value, you also need to supply the SQL filter syntax for it.
There are several ways that can be done, all outlined in the post linked to above.

| improve this answer | |
  • Thank you, the difference is I'm using a date field, callback did not work, can you tell me how would getCondition () the range of dates? – Dexxtz Nov 17 '14 at 14:04
  • Please update your post to include the code for the callback. – Vinai Nov 17 '14 at 14:06

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.