1

I have a List defined in a XML View. I bind the items of the list in the XML View but I want to define the filters in the JavaScript Code because the filters are to complex to define in XML. I create the filters in FilterUtils and now I want to set that array of filters as the filters of the list.

XML View:

 <List id="order-List" items="{path: '/OrderSet',filters : ???} inset="false" growingScrollToLoad="true" growing="true" growingThreshold="5">

FilterUtils:

jQuery.sap.declare("de.my.util.FilterUtils");

jQuery.sap.require("sap.ui.model.FilterOperator");

de.my.util.FilterUtils = {

    /**
     * Returns the filter to request all mobile relevant orders of the current work center
     */
    buildFilterServiceOrdersOfCurrentWorkcenter: function () {
        var filterMnWkCtr = new sap.ui.model.Filter("MnWkCtr", sap.ui.model.FilterOperator.EQ, de.my.Component.getMetadata().getConfig().myConfig.mnWkCtr);
        var filterUserstatus = new sap.ui.model.Filter("Userstatus", sap.ui.model.FilterOperator.EQ, 'ACT');
        var filterOrderType = new sap.ui.model.Filter([new sap.ui.model.Filter("OrderType", sap.ui.model.FilterOperator.EQ, 'AS1'), new sap.ui.model.Filter("OrderType", sap.ui.model.FilterOperator.EQ, 'AS2'), new sap.ui.model.Filter("OrderType", sap.ui.model.FilterOperator.EQ, 'AS3'), new sap.ui.model.Filter("OrderType", sap.ui.model.FilterOperator.EQ, 'AS4')], false);
        var filterServiceOrders = new sap.ui.model.Filter([filterMnWkCtr, filterUserstatus, filterOrderType], true);
        return filterServiceOrders;
    }
}
Jan Koester
  • 1,178
  • 12
  • 26

1 Answers1

0

Once you are done with creating all your filters just update the binding in your controller like this:

var list = this.getView().byId("order-List");
list.getBinding("items").filter(filters);
Tim Gerlach
  • 3,390
  • 3
  • 20
  • 39
  • I tried your solution but that leads to the problem that the list is filtered after the list is displayed so the list is refreshed twice. – Jan Koester Jun 29 '15 at 09:43
  • Ok, I got your point. You can circumvent this by omitting the items aggregation definition in your XML view and doing the initial binding after filter calculation in your controller. Unfortunately there´s is no better solution, yet. [This post](http://stackoverflow.com/q/25387580/1969374) refers to a slightly related problem. – Tim Gerlach Jun 29 '15 at 11:02