I\'m currently trying some stuff with/in SAPUI5 and I\'ve implemented a very simple search like this:
var filters = [];
var query = evt.getParameter(\"qu
For the requirement this code will work.
var list = this.getView().byId("list");
var binding = list.getBinding("items");
if( !query ) {
binding.filter( [] );
}
else {
binding.filter( [ new sap.ui.model.Filter([
new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query ),
new sap.ui.model.Filter("gender", sap.ui.model.FilterOperator.Contains, query )
],false)
]
I achieved this with the below code:-
var oFilter = new sap.ui.model.Filter("name",sap.ui.model.FilterOperator.Contains,searchString);
var oFilter1 = new sap.ui.model.Filter("ID",sap.ui.model.FilterOperator.Contains,searchString);
var comFil = new sap.ui.model.Filter([oFilter,oFilter1]);
var oList = sap.ui.getCore().byId("dealerList");
oList.getBinding("items").filter(comFil,sap.ui.model.FilterType.Application);
I hope I got everything right: Here is how filtering more than one column when binding data to a table:
oTable.bindRows({
path : "/modelData",
filters: [new sap.ui.model.Filter("severity", sap.ui.model.FilterOperator.EQ, '2'),
new sap.ui.model.Filter("severity", sap.ui.model.FilterOperator.EQ, '3')]
});
to combine multiple filters you've to write the filter this way:
new sap.ui.model.Filter({
filters: [
new sap.ui.model.Filter(col1, , ,val),
new sap.ui.model.Filter(col2, , ,val)
],
and: false
})
Source: https://sapui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.Filter.html#constructor
Then you can filter in multiple columns with OR.
Have only one filter in the filters
array for each of the criteria and it should work,
var filters = [];
var sFilter;
var query = evt.getParameter("query");
if (query && query.length > 0) {
if(query == "name" )
{
sFilter = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, query);
}
else if(query == "gender")
{
sFilter = new sap.ui.model.Filter("gender", sap.ui.model.FilterOperator.Contains, query);
}
//and so on...
filters.push(sFilter);
}
var list = this.getView().byId("list");
var binding = list.getBinding("items");
binding.filter(filters);
I had to use both. So at the end this worked for me.
var oFilters = new sap.ui.model.Filter({
filters: [
oFilter,
oFilter2
],
and: false
});
evt.getSource().getBinding("items").filter(oFilters, sap.ui.model.FilterType.Application);
Thanks for the help!