SAPUI5过滤器栏搜索带有多个组合框的过滤器组项目

时间:2019-04-03 03:20:46

标签: sapui5

aFilters array我尝试使用过滤器栏进行过滤,但该值未显示出来。没有错误,只是值不出来

onSearch: function(oEvent) {
    //get the filter bar from the event
    var oFilterBar = oEvent.getSource();

    //get the filter items from the filter bar
    var aFilterGroupItems = oFilterBar.getFilterGroupItems();

    //map the array of FilterItems to a new array of sap.ui.model.Filter objects
    var aFilters = aFilterGroupItems.map(function(oFilterGroupItem) {

        //get the filter item name (which is now the same as the filter property name)
        var sFilterName = oFilterGroupItem.getGroupName();

        //use the filter bar to get the control for the filter
        var oControl = oFilterBar.determineControlByFilterItem(oFilterGroupItem);

        //use the control to get the selected value (selected key)
        var sSelectedValue = oControl.getSelectedKeys();                

        var oFilter = new sap.ui.model.Filter(sFilterName, "EQ", sSelectedValue);

        return oFilter;
   });

   this.getView().byId("table").getBinding("items").filter(aFilters);
}

1 个答案:

答案 0 :(得分:0)

在SAP提供的Filter文档中,提到要合并多个过滤器(AND或OR),则应使用属性filters创建一个包含数组的新Filter对象您希望应用的已定义过滤器对象的数量。

根据该信息,您可以尝试在onSearch函数中添加以下代码(在关闭.map()之后):

var oFinalFilter = sap.ui.model.Filter({
    filters: aFilters, //aFilters = array of created Filter-objects
    and: true //true|false depending on requirements
});

并替换

this.getView().byId("table").getBinding("items").filter(aFilters);

通过

this.getView().byId("table").getBinding("items").filter(oFinalFilter);