cancel
Showing results for 
Search instead for 
Did you mean: 

sap.ui.model.Filter Custom Filter Function

ianfmccallum
Explorer
0 Kudos

Hello:

I am trying to create an sap.ui.model.Filter for a list of customers, on the value of an expanded element. Specifically, a Customer has multiple locations, and the US State is one of the elements of the location. The OData looks something like this:

[{"name": "Customer A", "locations": [{"city": "Los Angeles", "state": "CA"}, {"city": "Dallas", "state": "TX"}]}, {"name": "Customer B", "locations": [{"city": "Boston", "state": "MA"}, {"city": "San Francisco", "state": "CA"}]}]

The filter would be given a state, and return true if the customer has a location in that state

I think that filter (with a hard-coded value, obviously) would look something like this:

oFilters.push(new sap.ui.model.Filter({
   path: "locations",
   test: function(oValue) {
      var oLocations = oValue.getModel();
      for (var oLocation in oLocations) {
         if (oLocation.getProperty("state") === "CA") {
            return true;
         }
      }
      return false;
    }
}));

When I run the filter, I should get back [true, true] and then both "Customer A" and "Customer B" would be included in the results. I get nothing back (so everything passes) and I can't trace its actions.

Does anyone have experience with this? If you are wondering, this is trying to simulate the OData v4 'ANY' filter.

Accepted Solutions (1)

Accepted Solutions (1)

maheshpalavalli
Active Contributor
0 Kudos

you can write a debugger statement inside and check the data. I am not sure how you will get the data in the function parameter oValue and I think you will not get the model there, instead you will have the values. or that particular line. Better check in debugging, put a debugger statement.

ianfmccallum
Explorer
0 Kudos

Do you mean something like a console log statement?

maheshpalavalli
Active Contributor
0 Kudos

No it is straight "debugger" statement inside the function.. and click on f12 in chrome and refresh the page, which will trigger the debugger

ianfmccallum
Explorer
0 Kudos

I did try that...the statement in question doesn't get executed.

Answers (0)