alexP
alexP

Reputation: 3765

SAPUI5 Filter works only with Strings

I want to filter my list by TypeID but my ID's are numbers (int32) and the "Contains" filter doesn't work with numbers, i think.

onSearch : function (oEvt) {
    var sQuery = oEvt.getSource().getValue();
    var list = this.getView().byId("myList");
    var binding = list.getBinding("items");         

    if (sQuery && sQuery.length > 0) {
        binding.filter( [ new sap.ui.model.Filter([
           new sap.ui.model.Filter("TypeID", sap.ui.model.FilterOperator.Contains, window.global.TypeID  )    //Error: request failed due to invalid system query options value!
        ],false)]);
    }
},

Any help?

Upvotes: 0

Views: 4601

Answers (1)

jpenninkhof
jpenninkhof

Reputation: 1920

From an OData perspective, the filter operation "Contains" is translated to OData operation "substring". As the name of the operation already implies, it can only be used on strings. If you want to filter on non-strings, you will have to use the FilterOperator.EQ instead, but this doesn't allow you to filter on portions of the attribute.

If you need to filter on portions of a numerical attribute, e.g. 23 to find 1234, you will have to apply client side filtering and build a routine that does the filtering for you.

Instead of instantiating the filter using:

new Filter("TypeID", FilterOperator.Contains, typeID);

You will have to instantiate the filter using:

new Filter("TypeID", fnTest);

Please do note that client side filtering may lead to enourmous amounts of data being pulled from the back-end. So use it with caution.

Alternatively, you could of course also try to talk to the people in charge of the back-end logic, to see if they could redefine the search attribute as a string instead of a numerical value.

Upvotes: 1

Related Questions