0

I have the requirement to send filter values via OData-service, to fill a table with relevant entries. So basically there are input fields, where you can select e.g. "AA" (american airlines) for Carrier-ID.

So the filter values need to be created dynamically, regarding to the user input.

I tried following:

var aFilters = [
  new sap.ui.model.Filter({
    path: "Carrid",
    operator: sap.ui.model.FilterOperator.EQ,
    value1: "{selection>/Carrid}"
  })
];
oModel.read("/SFLIGHTSSet",{
  method: "GET",
  filters: aFilters,
  success: function(oData2, oResponse) {
    var oJSONModel = new sap.ui.model.json.JSONModel();
    oJSONModel.setData({
      modelData: oData2.results
    });
    oTable.setModel(oJSONModel);
    oTable.bindRows("/modelData");
  },
  error: function(oError) {
    console.log("Error!");
  }
});

But that doesn't work.
I receive in back-end following request:

"( Carrid eq '{selection>/Carrid}' )"

So the binding doesn't work in the filter-creation...

The binding is correct because I can use it the same way in a Label:

new sap.m.Label({
  text: "{selection>/Carrid}"
});

I researched a lot and know that people have problems with it in XML views.. but couldn't find any solution for JS-Views.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
user42932
  • 31
  • 2
  • 7
  • 1
    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 Feb 05 '18 at 16:49
  • Also take a look at this answer: https://stackoverflow.com/a/41782480/5846045. Since Filters (as well as Sorters) are not derived from ManagedObject, binding syntax doesn't work there. – Boghyon Hoffmann Feb 05 '18 at 16:52

1 Answers1

0

I guess your problem is in the line "{selection>/Carrid}"

Get the value of the User-Input from the Control somehow like this

var sCarrid= this.byId("MySelection").getBindingContext("selection").getProperty("Carrid");

and modify your Filter

var oFilters = [ new sap.ui.model.Filter("Carrid",
                            sap.ui.model.FilterOperator.EQ,
                            sCarrid) ];
A.vH
  • 881
  • 6
  • 10
  • Probably the better way would be to avoid accessing controls by the **id** and use model only: `var sCarrid= this.getView().getModel("selection").getProperty("/Carrid");`. – slkorolev Feb 08 '18 at 07:05