I am creating a CombiBox SearchAsYouType tied to a Store. It contains the input tokenization in words and a comparison (at the moment) with all the properties of the object:
{"id": "id_someid", "lastName": "Porker", "firstName": "Peter"}
I decided to create Filters on the fly when the changes to the list change:
Ext.define('MyApp.controller.SearchFilterController', { extend: 'Ext.app.Controller', views: [ 'SearchAsYouTypeCombo' ], configureFiltersBeforeQuery: function(queryPlan) { //add filter per word token comboBox = queryPlan.combo; queryString = queryPlan.query; words = queryString.split(/[,\s]+/); myStore = comboBox.getStore(); myStore.clearFilter(false); //I also tried without this line, did not help if(!Ext.isEmpty(queryString)) { //create a filter per word filters = []; Ext.Array.each(words, function(word, index, wordsArray){ console.log('NEW FILTER: word: ' + word); filterAllPropertiesFilter = Ext.create('Ext.util.Filter', { filterFn: function(item){ match = false; Ext.Object.each(item.data, function (property, value){ //match beginning of word match = match || (String(value).toLowerCase().lastIndexOf(word.toLowerCase(), 0) === 0); return !match; //do not check other properties when match is found }); return match; }}); filters.push(filterAllPropertiesFilter); return true; }, this, false); myStore.addFilter(filters); } return true; }, init: function(application) { this.control({ 'SearchAsYouTypeCombo': { beforequery: this.configureFiltersBeforeQuery } }); }
});
EDIT: There is a Kevin Bacon in my store. Let's say that none of the LastNames of others in the local store starts with "Ba", but there is someone else whose FirstName name is "Barry". So when I type in the search query “Ba”, I want to see the results of “Kevin Bacon” and “Barry White”. It works.
But here's what I can’t do: When I continue to expand searchString to “Ba, Ke”, I don’t want the code to interact again with all the Faces in my Store when applying the filter. I want the next filter to check only two results to the left of the previous filter. I kind of want to apply a filter to another filter.
source share