0

Here is the list of all FilterOperators: sapui5.netweaver.ondemand.com

My code:

var searchValue = "searching";

var myFilter = new sap.ui.model.Filter("var", sap.ui.model.FilterOperator.Contains, searchValue, false);

But this way, all items will be selected, if they include the string "searching" in the key "var". How can I write a filter, which is selecting items, only if they do not have the string searchValue in the key "var"?

Example:

  var = {(A,B,C), (B,C,D), (C,D,E)};
  searchValue = "A";

  //after filtering
  result = {(B,C,D), (C,D,E)};

1 Answer 1

0

It would be nice knowing what kind of model you are using. Anyway...

There is currently no "out of the box" support for this. What you can do is using the "test" property of sap.ui.model.Filter, which would be a function for your custom comparison (so you would implement what you want). This works fine for JSONModel. However, since OData is actually a server side model I assume that the implementation of the ODataModel will neglect the "test" function.

If you are using OData, then you have some benefits in general. The OData 2.0 spec allows "logical negations". For example, to get a list of all customers where the customer name does not contain "Al" you could call this:

http://services.odata.org/V2/Northwind/Northwind.svc/Customers?$filter=not substringof('Al', CompanyName)&$format=json

However, it seems that the ODataModel of UI5 currently does not have official support for this. I checked the code of sap.ui.model.odata.ODataUtils and there is no handling of the "logical negation". What you could do here is creating the URL string including the $filter with the logical negation manually and then executing a GET request on your own to get the data. An other option would be to extend UI5 itself, but I think this can get a little tricky here...

I guess this is worth a feature request at https://github.com/SAP/openui5/ :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.