我已经有了一个sap.m.list,它已经基于一个属性进行了过滤。现在我再次需要对该列表应用过滤器来实现实时搜索。
filterList:function(evt){
debugger;
var filters = [];
var oFilter="";
var query = evt.oSource.mProperties.value;
if (query && query.length > 0) {
var filter = new sap.ui.model.Filter("CLTYPE", sap.ui.model.FilterOperator.Contains, query);
filters.push(filter);
var filter1 = new sap.ui.model.Filter("CLCAT", sap.ui.model.FilterOperator.Contains, query);
filters.push(filter1);
var filter2 = new sap.ui.model.Filter("CLNUM", sap.ui.model.FilterOperator.Contains, query);
filters.push(filter2);
oFilter = new sap.ui.model.Filter( filters, false );
}
// update list binding
var list = sap.ui.getCore().byId("List");
var binding = list.getBinding("items");
binding.filter(oFilter);
},
此处我的列表已经过滤。其中list.getBinding('items')将为我提供所有项目,而不是已过滤的Items.I应用了我的sap.m.list过滤器,如下所示
obj[filterParam] = context;
var contextClauses=_.where(clauses,obj);
sap.ui.getCore().getModel('ClauseModel').setProperty("/DATA/CURRENTCLAUSES",contextClauses);
// update list binding
var list = sap.ui.getCore().byId("List");
var binding = list.getBinding("items");
binding.filter(oFilter);
如何实施?任何建议?
答案 0 :(得分:0)
将livechange
添加到textfield
并调用函数来过滤列表。
new sap.ui.commons.TextField({type:"Text",
value:"",
liveChange: function(oEvent){
//Now call a function to filter your list.
filterList(oEvent,oStorage.get("previousFilteredList"));
}});
filterList: function(oEvent,yourObj){
var like = oEvent.getParameter("liveValue");
var oFilter = new sap.ui.model.Filter("name",
sap.ui.model.FilterOperator.StartsWith,like);
var element = sap.ui.getCore().getElementById("sample");
var listBinding = element.getBinding("items");
listBinding.filter([oFilter]);
//Add the filtered object oStorage after every filter to access the previous filtered data
//oStorage.put("previousFilteredList","yourobj");
},
//Wherever you filter your data first.
oStorage = jQuery.sap.storage("session");
oStorage.put("previousFilteredList","yourobj");
答案 1 :(得分:0)
我认为你有两个选择:
创建初始筛选列表的新实例:
// assumes you have declared lists (initialList and newList)
// values between <..> should be replaced
jQuery.each (initialList, function (index, item) {
if (item.<someField> == <somevalue>) {
// you could add an additional field to the new list item like so:
item["<newFieldName"] = <newValue>;
if (item.<someOtherField> >= <someOtherValue>) {
newList.push(item); // adds this item to the new array / list
}
}
newListModel.setData(newList); // assumes newListModel has been created
//bind to control
答案 2 :(得分:0)
我用&#39;和&#39;解决了它。过滤条件
var mainFilter=new sap.ui.model.Filter(parameter,sap.ui.model.FilterOperator.Contains,context);
var query =evt.getParameter("newValue");
if (query && query.length > 0)var filter1= new sap.ui.model.Filter("CLNAME",sap.ui.model.FilterOperator.Contains,query);
filtersArr1.push(filter1);
filtersArr1.push(mainFilter);
var filter2 = new sap.ui.model.Filter("CLNUM",sap.ui.model.FilterOperator.Contains, query);
filtersArr2.push(filter2);
filtersArr2.push(mainFilter);oFilter1 = new sap.ui.model.Filter(filtersArr1,true);oFilter2 = new sap.ui.model.Filter(filtersArr2,true);filterGroup.push(oFilter1,oFilter2);oFilter4 = new sap.ui.model.Filter(filterGroup,false);
binding.filter(oFilter4);
工作精细
答案 3 :(得分:0)
var listFilter=new sap.ui.model.Filter(parameter,sap.ui.model.FilterOperator.Contains,context);
var query =evt.getParameter("newValue");
if (query && query.length > 0)
var filter1= new sap.ui.model.Filter({
new sap.ui.model.Filter("CLNAME",sap.ui.model.FilterOperator.Contains,query),
new sap.ui.model.Filter("CLNUM",sap.ui.model.FilterOperator.Contains, query)}, and:false),
var oFilter = new sap.ui.model.Filter( [filter1, listFilter], true)
binding.filter(oFilter);
});