Can't set a filter value using data binding?

This question arose from drilling the original question: How to set a filter in the table drop-down list based on table row data

Background

I want to use a filter in the SAPUI5 popup menu, where I set the filter value based on the model property (data binding)

Problem

If I use a filter, where the value1 filter value1 is determined by data binding :

 new sap.ui.model.Filter({ path : "division", operator : sap.ui.model.FilterOperator.EQ, value1 : "{/someProperty}" }) 

then the dropdown does not display any items

However, if I hardcode the value in the value1 property:

 new sap.ui.model.Filter({ path : "division", operator : sap.ui.model.FilterOperator.EQ, value1 : "Test" }) 

Then the filter works as expected.

Question

Is it true that we cannot use data binding to indicate a filter value? Or should I implement it differently?

A small part of me can understand that installing a filter on a control model using a value from the same model can cause some relational problems, but this behavior also occurs when using two different named models (one for the drop-down list and one for the filter value)

Any help is much appreciated!

+8
javascript sapui5
source share
2 answers

I just looked at the ClientListBinding code, unfortunately the property binding for the filter value is not supported. Check out the source code here .

See the getFilterFunction function, the filter value is obtained from your filter definitions oValue1 and oValue2 , it does not parse any DataBinding path to get the value from the DataModel.

 /** * Provides a JS filter function for the given filter * @name sap.ui.model.ClientListBinding#getFilterFunction * @function */ ClientListBinding.prototype.getFilterFunction = function(oFilter){ if (oFilter.fnTest) { return oFilter.fnTest; } var oValue1 = this.normalizeFilterValue(oFilter.oValue1), oValue2 = this.normalizeFilterValue(oFilter.oValue2); switch (oFilter.sOperator) { case "EQ": oFilter.fnTest = function(value) { return value == oValue1; }; break; case "NE": oFilter.fnTest = function(value) { return value != oValue1; }; break; case "LT": oFilter.fnTest = function(value) { return value < oValue1; }; break; case "LE": oFilter.fnTest = function(value) { return value <= oValue1; }; break; case "GT": oFilter.fnTest = function(value) { return value > oValue1; }; break; case "GE": oFilter.fnTest = function(value) { return value >= oValue1; }; break; case "BT": oFilter.fnTest = function(value) { return (value >= oValue1) && (value <= oValue2); }; break; case "Contains": oFilter.fnTest = function(value) { if (typeof value != "string") { throw new Error("Only \"String\" values are supported for the FilterOperator: \"Contains\"."); } return value.indexOf(oValue1) != -1; }; break; case "StartsWith": oFilter.fnTest = function(value) { if (typeof value != "string") { throw new Error("Only \"String\" values are supported for the FilterOperator: \"StartsWith\"."); } return value.indexOf(oValue1) == 0; }; break; case "EndsWith": oFilter.fnTest = function(value) { if (typeof value != "string") { throw new Error("Only \"String\" values are supported for the FilterOperator: \"EndsWith\"."); } var iPos = value.lastIndexOf(oValue1); if (iPos == -1){ return false; } return iPos == value.length - new String(oFilter.oValue1).length; }; break; default: oFilter.fnTest = function(value) { return true; }; } return oFilter.fnTest; }; 

I think you should go around in order to use an event handler.

+9
source share

No, it is currently not possible to set a data-bound filter value. However, there is an issue approval mark in the OpenUI5 repository, labeled as "welcome input." This means that it is planned to add this functionality, and after adding it will be possible to set the filter value using data binding.

0
source share

All Articles