cancel
Showing results for 
Search instead for 
Did you mean: 

add second filter without removing the existing ones

Former Member
0 Kudos

Hi i have a searchfield with this code behind it:

onSearch : function (oEvent) {
	if (oEvent.getParameters().refreshButtonPressed) {
	    // Search field's 'refresh' button has been pressed.
	    // This is visible if you select any master list item.
	    // In this case no new search is triggered, we only
	    // refresh the list binding.
	    this.onRefresh();
	} else {
		var andFilter = [];
		var sQuery = oEvent.getParameter("query");			        if (sQuery && sQuery.length > 0) {
		// add filters
		var oTableSearchState = [];
		oTableSearchState = [new Filter("Supplier", FilterOperator.Contains, sQuery),									     new Filter("BusArea", FilterOperator.Contains, sQuery),		     new Filter("CostCenter", FilterOperator.Contains, sQuery),
		     new Filter("FuncArea", FilterOperator.Contains, sQuery)		 ];
		andFilter.push(new Filter(oTableSearchState, false));
	        }
	        this._applySearch(andFilter);
       }
},

And a filter button that should add aditional filters. Something like this:

onSetFilter : function(oEvent) {
	var andFilter = [];
	andFilter.push(new Filter("BusArea", FilterOperator.EQ, "5000"));
	this._applySearch(andFilter);
},

But of course the "BusArea" part should be dependent on what filters are selected. It could be more than 1 filter. the _applySearch function looks like this:

_applySearch: function(andFilter) {
	var oViewModel = this.getModel("worklistView");
	this._oTable.getBinding("items").filter(andFilter, true);
	// changes the noDataText of the list in case there are no filter results
	if (andFilter.length !== 0) {
	    oViewModel.setProperty("/tableNoDataText", this.getResourceBundle().getText("worklistNoDataWithSearchText"));
	}
}

the problem is that when i add a filter via the filter button, the filters from the searchbar disappear and the other way arround. how can i change my code so that i can add the filters without removing the existing ones?

Accepted Solutions (0)

Answers (0)