SAPUI5: How to filter data with 2 or more values

前端 未结 9 1266
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 20:51

I\'m currently trying some stuff with/in SAPUI5 and I\'ve implemented a very simple search like this:

    var filters = [];
    var query = evt.getParameter(\"qu         


        
相关标签:
9条回答
  • 2021-02-04 21:19

    For the requirement this code will work.

    var list = this.getView().byId("list");
    var binding = list.getBinding("items");
    if( !query ) {
        binding.filter( [] );
    } 
    else {
       binding.filter( [ new sap.ui.model.Filter([
          new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query ),
          new sap.ui.model.Filter("gender", sap.ui.model.FilterOperator.Contains, query )
       ],false)
    ]
    
    0 讨论(0)
  • 2021-02-04 21:19

    I achieved this with the below code:-

    var oFilter = new sap.ui.model.Filter("name",sap.ui.model.FilterOperator.Contains,searchString);
    var oFilter1 = new sap.ui.model.Filter("ID",sap.ui.model.FilterOperator.Contains,searchString);
    var comFil = new sap.ui.model.Filter([oFilter,oFilter1]);
    var oList = sap.ui.getCore().byId("dealerList");
    oList.getBinding("items").filter(comFil,sap.ui.model.FilterType.Application);
    
    0 讨论(0)
  • 2021-02-04 21:19

    I hope I got everything right: Here is how filtering more than one column when binding data to a table:

    oTable.bindRows({
        path : "/modelData",
        filters:  [new sap.ui.model.Filter("severity", sap.ui.model.FilterOperator.EQ, '2'),
                   new sap.ui.model.Filter("severity", sap.ui.model.FilterOperator.EQ, '3')]  
    });
    
    0 讨论(0)
  • 2021-02-04 21:24

    to combine multiple filters you've to write the filter this way:

    new sap.ui.model.Filter({
        filters: [
        new sap.ui.model.Filter(col1, , ,val),
        new sap.ui.model.Filter(col2, , ,val)
        ],
        and: false
    })
    

    Source: https://sapui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.Filter.html#constructor

    Then you can filter in multiple columns with OR.

    0 讨论(0)
  • 2021-02-04 21:24

    Have only one filter in the filters array for each of the criteria and it should work,

    var filters = [];
    var sFilter;
    var query = evt.getParameter("query");
    if (query && query.length > 0) {
    
        if(query == "name" )
        {
           sFilter = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query);
        }
        else if(query == "gender")
        {
           sFilter = new sap.ui.model.Filter("gender", sap.ui.model.FilterOperator.Contains, query);
        }
         //and so on...
    
        filters.push(sFilter);
    }
    
    var list = this.getView().byId("list");
    var binding = list.getBinding("items");
    binding.filter(filters);
    
    0 讨论(0)
  • 2021-02-04 21:35

    I had to use both. So at the end this worked for me.

    var oFilters = new sap.ui.model.Filter({
                    filters: [
                        oFilter,
                        oFilter2
                    ],
                    and: false
                });
    evt.getSource().getBinding("items").filter(oFilters, sap.ui.model.FilterType.Application);
    

    Thanks for the help!

    0 讨论(0)
提交回复
热议问题