Skip to Content
0

add second filter without removing the existing ones

Apr 19, 2017 at 08:08 AM

26

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers