cancel
Showing results for 
Search instead for 
Did you mean: 

Dataset with multiple filter

0 Kudos

Hi All,

I am currently implementing a DataSet application.

According to the dev guide (https://sapui5.netweaver.ondemand.com/sdk/#test-resources/sap/ui/ux3/demokit/DataSet.html)

I managed that the filter is working fine, as described above.

search: function search(oEvent) {
               
var sQuery = oEvent.getParameter("query");
               
var oBinding = oDataSet.getBinding("items");
                oBinding
.filter(!sQuery ? [] : [new sap.ui.model.Filter("title", sap.ui.model.FilterOperator.Contains, sQuery)]);
                oDataSet
.setLeadSelection(-1);
       
},

By this solution it is only possible to search for a specific bound property/attribute. Now I would like to search for ALL attributes.

E.g:  "title" and "systemtype" at the same time.

Let say there is an item with title="NetWeaver Administrator" and another one with systemtype= "NWDI"

So when I would trigger the search with "N" all both items should be displayed....

when triggering the search with "NW" only one item should be displayed.

In words: I want to search that either matches the title-value or the systemtype-value.

I tried following

search: function search(oEvent) {
               
var sQuery = oEvent.getParameter("query");
               
var oBinding = oDataSet.getBinding("items");
                oBinding
.filter(!sQuery ? [] : [new sap.ui.model.Filter("title", sap.ui.model.FilterOperator.Contains, sQuery),

                                                           new sap.ui.model.Filter("systemtype", sap.ui.model.FilterOperator.Contains, sQuery)

                ]);
                oDataSet
.setLeadSelection(-1);
       
},

But this seems to display only those items where "title" AND "systemtype" matches.

Does anyone have an idea how to archieve this.

Regards,

Jens

Accepted Solutions (1)

Accepted Solutions (1)

konstantin_anikeev
Active Contributor
0 Kudos

Hi Jens,

not really sure, but try to add 2 "systemtype" filters.

see an example https://sapui5.hana.ondemand.com/sdk/#test-resources/sap/ui/core/samples/databinding/DataBindingTree...

Regards

Konstantin

0 Kudos

Hi Konstantin,

thanks for the reply, but I think Tree and DataSet implement the filter method differently.

For Tree is seems to be a OR-Filter, for DataSets it is an AND-Filter.

Does anyone else have a workaround?

Thx and regards,


Jens

former_member182372
Active Contributor
0 Kudos

* new sap.ui.model.Filter(aFilters, bAnd);

*

* aFilters is an array of other instances of sap.ui.model.Filter. If bAnd is set all filters within the filter will be ANDed else they will be ORed.

oBinding.filter(

          !sQuery ? [] : [

new sap.ui.model.Filter(

              [

                new sap.ui.model.Filter("title", sap.ui.model.FilterOperator.Contains, sQuery),

                new sap.ui.model.Filter("category", sap.ui.model.FilterOperator.Contains, sQuery)

              ],

              false)

]
  );
0 Kudos

Hi Maksim,

yes, this is the solution. Thank you!

I finally found this hint in the developer guide as well, but I really needed to search for it 😉

I figured out, that there is a bug in SAPUIVersion 1.12.5 and filtering is not working as desired.

But it is working now with 1.16.6.

Puahhh!!!

Got my Problems solved now. Perfekt!

Regards,

Jens

Answers (0)