首页 > 解决方案 > SAPUI5过滤器栏搜索过滤器组项目与多组合框

问题描述

aFilters 数组我尝试使用过滤器栏进行过滤,但值没有出来。没有错误,只是值不出来

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

标签: sapui5

解决方案


在SAP 提供的过滤器文档中,提到如果您想组合多个过滤器(AND 或 OR),您应该创建一个新的过滤器对象,其属性filters包含您希望应用的已定义过滤器对象的数组。

根据该信息,您可以尝试在 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);

推荐阅读