
Originally Posted by
Bunchofstring
Here's my idea: You seem to suggest that applying filters is fast, but clearing them is slow. By that logic, if the list only responds to <em>applying </em>filters to the bound store, performance would be fine. So... what if you had two stores with the same collection of records, and use one like a buffer?<br>
<br>
The following approach assumes that a list gets updated quickly when it is bound to a new store. On keyup, try this (<strong>untested/pseudo-code</strong>):<br>
Code:
var boundStore = list.getStore();<br>
//Set up on both stores so they can reference each other<br>
var bufferStore = boundStore.getTwinStore();<br>
//TRUE if backspace was pressed or the user inserted a character into the middle of the search string<br>
var requiresClear = (newValue.indexOf(oldValue) == 0);<br>
<br>
if(!requiresClear){<br>
//If filters are already in place for "a", it's probably more efficient to just add ones for "ap", "app", etc.<br>
boundStore.filter('name',newValue);<br>
}else{<br>
list.setStore(bufferStore);<br>
bufferStore.filter('name',newValue);<br>
//Might help to do the clear it's own "thread" (i.e. setTimeout)<br>
boundStore.clearFilter(true);<br>
}
<br>
<br>
That may be a crazy/foolish idea but it's worth a shot. One thing to watch out for is if the user pushes backspace a bunch of times (after the first backspace, the swapping and clearing would probably <em>hurt</em> performance).
Hi, I have the similar problem. I feel your technique might help me to improve performance a bit. Being honest, I am newbie to Sencha, worked in couple of sencha touch projects but this one sucks. It has 1500 records, displayed on a list need to be filtered.
But, the filtering of data is quite slow. I wanted to use your logic to my code. But I really felt bit difficult to understand. If you could help me to fix my problem, I will really be very glad. Thanks in advance.
Here is my filter logic, while user presses key in text field.
Code:
onSearchKeyUp: function(field) {
//get the store and the value of the field
var value = field.getValue(),
store = Ext.getStore("storeid");
//first clear any current filters on thes tore
store.clearFilter();
//check if a value is set first, as if it isnt we dont have to do anything
if (value) {
//the user could have entered spaces, so we must split them so we can loop through them all
var searches = value.split(' '),
regexps = [],
i;
//loop them all
for (i = 0; i < searches.length; i++) {
//if it is nothing, continue
if (!searches[i]) continue;
//if found, create a new regular expression which is case insenstive
//regexps.push(new RegExp(searches[i], 'i'));
// to make starts with search
regexps.push(new RegExp("^"+searches[i], 'i'));
}
//now filter the store by passing a method
//the passed method will be called for each record in the store
store.filter(function(record) {
var matched = [];
//loop through each of the regular expressions
for (i = 0; i < regexps.length; i++) {
var search = regexps[i],
didMatch = record.get('term').match(search);
//if it matched the first or last name, push it into the matches array
matched.push(didMatch);
}
//if nothing was found, return false (don't so in the store)
if (regexps.length > 1 && matched.indexOf(false) != -1) {
return false;
} else {
//else true true (show in the store)
return matched[0];
}
});
}
}