1

In my App I have a Microchart which is directly bound to an OData-Entityset in the XML View.

I now want to pass a Filter to that Request. But this filter should be dynamic based on what settings the user selected.

The user selects a timeframe and this value is then stored in another View Local JSON Model.

Is it possible to build the OData Binding Filter based on that value.

Here the binding with filter which wont work.

I tried various combinations:

  • {filterModel>/status}
  • {path: 'filterModel>/status' }
<microchart:InteractiveDonutChart id="microDonutChart"
        segments="{path: '/BookingStOverviewSet', 
                   filters : [ 
                       { path : 'Txt04', 
                         operator : 'GE', 
                         value1 : {filterModel>/status} 
                       } 
                   ]
                  }">
    <microchart:segments>
     <microchart:InteractiveDonutChartSegment label="{Txt30}" value="{Count}"/>
    </microchart:segments>
</microchart:InteractiveDonutChart>

The logic in the controller to build the JSON Model with the Filter values:

onInit: function () {
    var filterModel = new sap.ui.model.json.JSONModel(
             {
               "startOfCal": new Date(),
               "endOfCal": new Date(), 
               "status": '0001'
            });

    this.getView().setModel(filterModel, 'filterModel');
}
Daniel
  • 109
  • 1
  • 9
  • Does this answer your question? [How to bind filter values in XML view](https://stackoverflow.com/questions/41777791/how-to-bind-filter-values-in-xml-view) – Boghyon Hoffmann Jul 17 '21 at 19:32

2 Answers2

1

Dynamic filtering via XML is sadly not supported by SAPUI5, you'll need to do work around that in the JS part of the application.

pguddi
  • 325
  • 2
  • 3
  • 11
0

The work around can be developed in this way:

var filters = [];
var myFilter= new sap.ui.model.Filter("Txt04", sap.ui.model.FilterOperator.EQ, filterModel.getProperty("/status"));
            filters.push(myFilter);
var microChart = this.getView().byId("microDonutChart") 
microChart.bindSegments({
                path: "/BookingStOverviewSet",
                filters: filters,
                template: microChart.getBindingInfo("items").template
            });
fareslt
  • 191
  • 1
  • 6