PDA

View Full Version : Store Filters with AND/OR Logic



billtricarico
14 Aug 2012, 2:11 PM
Hello,

In building a series of filters for a store, I am having difficulty building a filter that combines AND and OR logic. It seems the store.filter() accepts an array of Filter objects and applies then in an AND fashion (filter1 AND filter2 AND filter3...)

Can a store filter be built that mixes ANDs and ORs? I have a series of combo boxes that will be the ANDs. I also have a grid panel with multi-select. These will be the ORs. Something like this:

combo1.value AND combo2.value AND combo3.value AND (grid.selectedItem1 OR grid1.selectedItem2).

Thanks.

billtricarico
14 Aug 2012, 2:29 PM
I used a filter function to solve this. The filter function handles the OR case.

My code:



var store = this.getGridToFilter().getStore();
var filters = [];
var selections = this.getMultiSelectGrid().getSelectionModel().getSelection();


if (selections.length > 0)
{
var f = new Ext.util.Filter({
filterFn: function(item) {


var anyMatch = false;

Ext.each(selections,function(selection){

anyMatch = anyMatch | item.get('IdToTest') === selection.get('SelectionId');
});

return anyMatch;
}
});
filters.push(f);

// ... other AND filters
}

store.clearFilters();
store.filter(filters);