question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data binding not supported for sap.ui.model.Filter value1/value2 properties

See original GitHub issue

UI5 Version 1.22.3 (built at , last change) User Agent Chrome/36.0.1985.143

Reproducable example: http://jsbin.com/nehato/2/edit?js,output

See also: http://stackoverflow.com/questions/25387580/not-possible-to-set-filter-value-using-data-binding

Steps to reproduce:

If I use a filter where the filter value value1 is specified by data binding:

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

then the dropdown does not render any items

However, if I hardcode a value at property value1:

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

then the filter works as expected.

Possible root-cause:

As Allen Zhang discovered in the aforementioned Stackoverflow topic, the Filter’s properties oValue1 and oValue2 do not parse any data binding path:

/**
 * 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);
    //etc...

(Source code here: https://openui5.hana.ondemand.com/resources/sap/ui/model/ClientListBinding-dbg.js)

Reasoning why it should work with databinding

Imagine you have a table, and one of the columns shows a dropdown box for each entry in the table. The entries in the dropdown box have to be filtered based on a value in the current table row (for instance, each row in the table has a client field, and the dropdown should only list the projects for that corresponding client: screen shot 2014-08-20 at 08 53 33

In code:

oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({
        text: "Projects"
    }),
    template: new sap.ui.commons.DropdownBox({
        selectedKey: "{tablemodel>project}",
        items: {
            path: "metadatamodel>/allprojects",
            template: new sap.ui.core.ListItem({
                text: "{metadatamodel>projectDescription}",
                key: "{metadatamodel>projectKey}"
            }),
            filters: [new sap.ui.model.Filter("projectClient", sap.ui.model.FilterOperator.EQ, "{tablemodel>client}")]
        }
    })
}))

Explanation

  1. The table records contain, among others, a field client and project
  2. The dropdown template control in the table column is bound to a property allprojects which contains an array of objects {projectKey : "zzz", projectDescription : "zzz", projectClient : "someClient"}
  3. The dropdown template has a filter, which filters the dropdown’s model property projectClient based on the corresponding table model array item’s property client

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:7
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
eckercommented, Aug 4, 2017

@rikusv @qualiture It’s been quite a while that this feature request had been brought up. Thanks for all your input and we apologize for the delays. Now we started to review the topic with our binding experts, again. Unfortunately, we don’t see to address it properly and suggest to keep using more explicit coding, typically in the controller.

Some reasons why we no longer consider an implementation (even that we had plans to do so back then): In order to benefit from the existing data binding capabilities one would turn the rather simple Filter objects into ManagedObjects (instead of reimplementing relevant parts in a redundant way). Only the comprehensive feature set of ManagedObject would allow to address reasonably powerful binding expressions in a dynamic filter. Just to use limited binding features wouldn’t cover some expected, real-life scenarios, e.g. referring to another model within the binding expression. Thus, one would need to have full lifecycle support for model creation, binding updates, etc. How and when to process different binding updates isn’t straightforward. Such implicit behavior could trigger some awkward update effects in (non-trivial) apps.

Therefore, in many real app scenarios we still advise to keep having more control about (re-)applying an updated filter or a set of filters, respectively. We suggest to go for the typical coding, albeit less elegant than the proposed dynamic filter declaration. As an example along those lines:

  • if model isn’t available yet, attach to modelContextChange event in control
  • use bindProperty() to create bindings for the filter values
  • attach to change event of those bindings
  • in handler (re-)create filter objects with those values
  • (re-)apply those filter objects on the binding to be filtered

Hope that helps, and the more explicit coding also comes with some benefits (such as more control and less implicit update flows).

6reactions
matzeeablecommented, Aug 22, 2016

Is there any feature update yet? Or a “workaround” for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data binding not supported for sap.ui.model.Filter value1 ...
I basically want to pass something like this to my gateway to get the filtered set of values. /sap/opu/odata/SAP/ZORDER_STATUS_SRV/ ...
Read more >
sap.ui.model.Filter - API Reference - Demo Kit - SAPUI5 SDK
A path , operator and one or two values ( value1 , value2 ), depending on the operator; A path and a custom...
Read more >
Not possible to set Filter value using data binding?
I just went through the code of ClientListBinding, unfortunately the property binding for Filter value is not supported.
Read more >
Table binding in sapui5 - Caritas Castellaneta
Table to adding some sorters and filters. Tutorial on how to build SAP-Fiori like UIs with SAPUI5 in 10 exercises. Part 1: SAPUI5...
Read more >
Sapui5 Smart Filter Bar - Schimpfkarten
I'm using the RAP framework with a Fiori Freestyle app (In SAP Business ... need to bind your table to an entity set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found