0
votes

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.

1
Also take a look at this answer: stackoverflow.com/a/41782480/5846045. Since Filters (as well as Sorters) are not derived from ManagedObject, binding syntax doesn't work there.Boghyon Hoffmann

1 Answers

0
votes

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) ];