View Full Version : Filter Function not working?

25 Feb 2014, 1:05 PM
Hello all,

I am trying to filter a store by more than one string on a search box by using the following code:

var strs = filterBox.value.split(' ');

syslogStore.filterBy(function(record) {

for (var i = 0; i < strs.length; i++) {
var r = record.getData();
return r.syslog_timestamp.toLowerCase().indexOf(strs[i]) !== -1 ||
r.app_name.toLowerCase().indexOf(strs[i]) !== -1 ||
r.username.toLowerCase().indexOf(strs[i]) !== -1 ||
r.usermac.toLowerCase().indexOf(strs[i]) !== -1 ||
r.message.toLowerCase().indexOf(strs[i]) !== -1;

however it will only filter for the first string passed, for example if I type in 'John Smith' on the search box, it will only return records containing 'John', could someone please tell me how to fix my code? or if there is an easier to way to apply multiple filters at the same time? Any help would be great, thank you.

25 Feb 2014, 3:16 PM
Ok so I changed it to this:

var strs = filterBox.value.split(' ');

syslogStore.filterBy(function(record, id){

if(Ext.Array.indexOf(strs, record.get('username')) !== -1){
return true;
return false;
}, this);

and that works, my only problem now is that I need it to return records which contain my search strings even if it's not an exact match, for example, if I search for the string 'use' a record with the username 'senchauser' should be returned, but right now it will only return it if I search for that exact string. Could someone please help me out with this?

26 Feb 2014, 7:41 AM
Perhaps if you for/loop the array and check for the indexOf > -1 (instead of Ext.Array.IndexOf)

26 Feb 2014, 9:08 AM
that worked, thanks Scott