cancel
Showing results for 
Search instead for 
Did you mean: 

Asterix in SAPUI5 with filter does OR, not AND

Former Member
0 Kudos

Hi all,


I want to implement a search in SAPUI5. There you can use the asterix () like in SAP.</p><p>So for example, if you want don't know the exact string you could write "HansHuber". So everything which starts with "Hans" and ends with "Huber" should be found.

With the filters in SAPUI5 there is the open with startsWith, endsWith - so this is no problem. But the problem is, that it does a OR relation and not a AND relation.

Here is the parameter string I get for the above example:

((startswith(BeCode,'HANS') or endswith(BeCode,'HUBER')))


As you can see, there is an OR but I need an AND. Could it be, that is automatically an OR because I want to filter two times on the same attribute (BeCode)? By default, SAPUI5 does the filter relation with AND - if you want to OR you have explicit set a flag.


Somebody any idea?


Thank you in advance,

Bastian

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Bastian,

There is an argument available in sap.ui.model.filter as 'and'. 

API (Check the last argument) - JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.Filter

You have to say something like this:


new sap.ui.model.Filter({

filters: [arrayOfFilters],

and: true               //change to false to set it 'or'

});

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi,

thanks. Found it myself in the same second you wrote it

Pushed all filters into an array:

aFilters.push(oFilter);

and afterwards created a new filter with the set of the above filters and the boolean value.

var oFilters1 = new sap.ui.model.Filter(aFilters, true);

Now everything is fine

Thanks,

Bastian

Answers (1)

Answers (1)

xyla
Participant
0 Kudos

Hi Bastian,

When building your filter, you can set it to use AND instead of OR as a conjunction. Please refer to the API:

https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.Filter.html

This line is interesting for you:

{boolean}oFilterInfo.and

indicates whether an "and" logical conjunction is applied on the filters. If it's set to false, an "or" conjunction is applied

Hope this helps!

Regards,

Szilamér