1

Hi i have an object with the data like

{
 status : [ "started", "completed"],
 branch : [ "India", "Germany" ]
}

here i want to construct nested filters like the status is either started OR completed AND the branch is either India OR Germany

i tried with the code below

var oFilter = new sap.ui.model.Filter(
   keys.forEach(function(v) {
     var oItem = totalFilterValues[v];
     if(v === "status"){
         return new sap.ui.model.Filter(oItem.forEach(function(val) {

              return new sap.ui.model.Filter("status",   
                  sap.ui.model.FilterOperator.Contains, val);

      }), false);
    } 

    if(v === "branch"){
         return new sap.ui.model.Filter(oItem.forEach(function(val) {

              return new sap.ui.model.Filter("branch",   
                  sap.ui.model.FilterOperator.Contains, val);

      }), false);
    } 

  }),true);

but was not working can you help me in this. i followed to the below code snippet.

    var oFilter = new sap.ui.model.Filter(mFacetFilterLists.map(function(oList) {
      return new sap.ui.model.Filter(oList.getSelectedItems().map(function(oItem) {
        return new sap.ui.model.Filter(oList.getTitle(), "EQ", oItem.getText());
      }), false);
    }), true);
Osamah Aldoaiss
  • 238
  • 4
  • 16
user1665207
  • 61
  • 1
  • 6

1 Answers1

1

For multiple Filters:

var oStatusFilter = new sap.ui.model.Filter('status', function(oValue) {
    if (oValue === "started" || oValue === "completed")
        return true;
    else return false;
});
var oCountryFilter = new sap.ui.model.Filter('branch',
    function(oValue) {
        if (oValue === "India" || oValue === "Germany")
            return true;
        else return false;
    }
);
var oFilters = new sap.ui.model.Filter([oCountryFilter, oStatusFilter], true
});

Read more here SAPUI5 Filters

Sunil B N
  • 4,159
  • 1
  • 31
  • 52
  • thank you for reply, but here iam not using facet filter iam getting the values as mentioned above and i need to loop through the values i need to prepare the filters, here is the place iam facing problem. – user1665207 Jun 14 '15 at 11:12
  • Oh OK. Let me re-code. Will be posting later. I'm Outside – Sunil B N Jun 14 '15 at 11:37