7

I am binding an OData model to the items of a list and try to apply a filter dynamically using the following syntax in an XML view:

<List
    id="supplierList"
    items="{
        path : '/SupplierCollection',
        filters : {
            path : 'CompCode',
            operator : 'EQ',
            value1: {
                path : 'general>/companyCode'
            }
        }
    }"

The "general" model used here has been defined in the Component.js and is also referenced in the controller of the view:

onInit : function() {
    ...
    var generalModel = sap.ui.getCore().getModel("general");
    this.getView().setModel(generalModel, "general");
    ...
}

Unfortunately, the model doesn't seem to be parsed and the path is not interpreted correctly at runtime. But if I hard-code the value1 then the filter works properly.

Any idea on this issue?

Is it me using a wrong path to set the value1 of the filter? Or is it a bug?

Unihedron
  • 10,902
  • 13
  • 62
  • 72
jao6693
  • 101
  • 1
  • 2
  • 6
  • Possible duplicate of [Not possible to set Filter value using data binding?](https://stackoverflow.com/questions/25387580/not-possible-to-set-filter-value-using-data-binding) – Boghyon Hoffmann Jul 05 '18 at 11:32

2 Answers2

4

Obviously Allen's answer is the correct way to go long term, but meanwhile I used the following work around in my controller:

onInit: function() {
    this._oView = this.getView();

    // ... any other init stuff ...

    this._oView.attachAfterRendering(function() {
        var sValue1 = "filter val";

        var sPath = "fieldName";
        var sOperator = "EQ";

        var oBinding = this.byId("catalogTable").getBinding("items");
        oBinding.filter([new sap.ui.model.Filter(sPath, sOperator, sValue1)]);
    });
}

Only one call is made to the service (it doesn't load the data and then reload which I feared it might).

lewis
  • 2,936
  • 2
  • 37
  • 72
1

The list binding does not support defining dynamic Filter value as a binding path. For details,please check my answer for this question. Also see the reported git issue at here.

Community
  • 1
  • 1
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • Sadly the implementation got rejected, because it would cause problems in non trivial apps as the required use of ManagedObjects would appear. I'm not deep enough into that topic to rate this decision, though. – Martin Braun Aug 07 '17 at 14:57