在UI5中过滤数据

时间:2017-01-17 10:55:47

标签: sapui5 sap-fiori

使用以下代码的过滤器无效。我使用Web IDE中的模板创建了一个应用程序,然后将OData绑定到XMLView中的列表,在搜索上应用过滤器。

查看:

<SearchField liveChange="onSearch" id="master1SearchField" search="onSearch"/>  
<List id="master1List" items="{path:'/DetailsSet'}">
    <items>
        <ObjectListItem id="master1ListItem">
            <attributes>
                <ObjectAttribute text="{Name}"/>                            
            </attributes>
        </ObjectListItem>
    </items>
</List>

控制器:

onSearch : function(oEvent) {
    var sFilteredValue = oEvent.getSource().getValue();
    var oFilter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, sFilteredValue);
    var oElement = this.getView().byId("table");
    var oBinding = oElement.getBinding("items");
    oBinding.filter([oFilter]);             
}

2 个答案:

答案 0 :(得分:1)

您需要绑定需要应用过滤器的项目。

var oElement = this.getView().byId("master1List"); 

应该解决问题。

答案 1 :(得分:-1)

尝试在设置过滤器后强制更新控件:

oBinding.refresh(true);