<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>Walkthrough</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.sample": "./"
}' >
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName : "sap.ui.sample.App"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
Filter sap.m.List with two filters. The filters are concatenated with 'or'.
The second filter filters a value which has been formatted on client-side.
<mvc:View
controllerName="sap.ui.sample.App"
xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc">
<List id="companiesList" items="{/companies}">
<headerToolbar>
<Toolbar>
<Title text="Companies"/>
<ToolbarSpacer/>
<SearchField width="50%" search="onFilterCompanies"/>
</Toolbar>
</headerToolbar>
<items>
<StandardListItem
title="{name}"
description="{
path: 'publ',
formatter: '.formatPublicFlag'
}"
/>
</items>
</List>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/m/List",
"sap/m/StandardListItem",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator"
], function (Controller, JSONModel, List, StandardListItem, Filter, FilterOperator) {
"use strict";
return Controller.extend("sap.ui.sample.App", {
onInit : function () {
// set data model on view
var oData = {
companies : [
{
name : "Acme Inc.",
zip : "03301",
city: "Belmont",
county: "Belknap",
state: "NH",
revenue : 123214125.34,
publ: true
},
{
name : "Beam Hdg.",
zip : "03451",
city: "Hancock",
county: "Sullivan",
state: "NH",
revenue : 3235235235.23,
publ: true
},
{
name : "Carot Ltd.",
zip : "03251",
city: "Cheshire",
county: "Sullivan",
state: "NH",
revenue : "Not Disclosed",
publ: false
}
]
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel);
},
onFilterCompanies : function(oEvent) {
var sQuery = oEvent.getParameter('query'),
oList = this.getView().byId("companiesList"),
oBinding = oList.getBinding("items");
if (sQuery) {
var aFilter = [],
fnTestPubl = function(bPublic) {
// use formatPublicFlag to reproduce
// formated value, then check if it contains 'sQuery'
// compare uppercase strings since filter be case insensitive
return this.formatPublicFlag(bPublic).toUpperCase().indexOf(sQuery.toUpperCase()) >= 0;
}.bind(this); // make sure 'this' inside the function refers to the
// controller
aFilter.push(new Filter("name", FilterOperator.Contains, sQuery));
aFilter.push(new Filter("publ", fnTestPubl, FilterOperator.Contains, sQuery));
// Create a filter which contains our name and 'publ' filter
// an concatenates them with 'or'
oBinding.filter(new Filter({filters: aFilter, and: false}));
} else {
// Use empty filter to show all list items
// oBinding.filter(new Filter([])); does not work
oBinding.filter([]);
}
},
formatPublicFlag: function(bPublic) {
return bPublic ? "Public" : "Private";
},
});
});