OrCondition in datagrid filter

Login or register to post comments
6 replies [Last post]
Offline
Joined: 08/12/2009

Hi,

Can I set a OrCondition in a datagrid filter - I'm getting a

Undefined GET property or variable in 'QQConditionOr' class: mixOperand

error. Any ideas?

Offline
Joined: 03/31/2008

No, you can't use an Or, because which of its children would the user's input apply to?

What are you trying to accomplish? Sometimes there are workarounds we can come up with.

Offline
Joined: 08/12/2009

In my case, I'd like the user's input to apply to both children.

Example: I have a datagrid for invoices and there's a column for Client (every invoice belongs to a specific client) - when the user filters by client, I want the filter to search on the client's Id and client's Name.

vakopian's picture
Offline
Joined: 04/08/2008

Here is what you could do:

<?php
class QDGConditionOr extends QQConditionComparison {
    protected
$arrConditions;
   
    public function
__construct(/* list of QQConditionComparison objects*/) {
       
$this->arrConditions = func_get_args();
    }

    public function
UpdateQueryBuilder(QQueryBuilder $objBuilder) {
        foreach (
$this->arrConditions as $condition) {
           
$condition->mixOperand = $this->mixOperand;
        }
       
QQ::OrCondition($this->arrConditions)->UpdateQueryBuilder($objBuilder);
    }
}
?>

then when setting up the data grid

<?php
$col
->Filter = new QDGConditionOr(QQ::Like(QQN::Client()->Id, null), QQ::Like(QQN::Client()->Name, null));
?>

Offline
Joined: 08/12/2009

Vakopian, thanks! It's working great!

One thing though: unlike the default text filters, this one only works on exact matches and won't search in substrings. Example:

client id is "1" and name is "John Doe", if I search for "1" or "John Doe" I get a match, but if I search for "Doe" no matches are returned.

Where can I change this behaviour? There must be a place to add some wildcards "%", right?

vakopian's picture
Offline
Joined: 04/08/2008

Yes, you can use

<?php
$col
->FilterPrefix = '%';
$col->FilterPostfix = '%';
?>

Offline
Joined: 08/12/2009

perfect! thank you