Reputation: 2030
I have a JSON model like this:
{
"VEHICLES": [
{
"vehicleId": "0001",
"routeName": "Ginza Line"
},
{
"vehicleId": "0002"
"routeName": "Another Line"
}
}
I am implementing a sort function like this:
onSearch : function (oEvent) {
var sQuery = oEvent.getParameter("query");
if (sQuery) {
var oFilter1 = new Filter("vehicleId", function(value) {
return value.includes("sQuery");
});
var oFilter2 = new Filter("routeName", function(value) {
return value.includes("sQuery");
});
var allFilter = new Filter([oFilter1, oFilter2], false});
var list = this.getView().byId("masterList");
list.getBinding("items").filter(allFilter);
}
}
When I input "000" in search field, I am expecting to return both data items, but it returns none. Why?
I have tried single "vehicleId" filter, it worked.
I have also tried
var allFilter = new Filter({
filters: [oFilter1, oFilter2],
and: false //OR
});
But allFilter.bAnd returned undefined
, I am confused.
Ref:
https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Filter.html
https://github.com/SAP/openui5/issues/1442
Upvotes: 1
Views: 2443
Reputation: 5713
Update:
according to API document. Put the parameter to Array
list.getBinding("items").filter([allFilter]);
@boghyon found from the source code here that it is actually got converted to Array
Upvotes: 0
Reputation: 2030
Thanks to @boghyon and @suryabhan mourya, I changed the fnTest
function to
var oFilter1 = new Filter("vehicleId", function(value) {
return value.includes(sQuery.toUpperCase());
});
and it's working!
Upvotes: 0
Reputation: 18044
There is a small mistake. You are checking if the vehicleId
includes the string "sQuery"
. Remove the quotes around sQuery and the filters will work fine.
value.includes(sQuery);
Upvotes: 1