This project is read-only.

Filter suggestion

Oct 12, 2010 at 10:48 PM

I would like to suggest adding a configuration option to allow matches to occur anywhere in the name text, rather than just at the beginning.

For example, given a config option called matchBeginning, modify the filter function like this:

              function filter(data, params) {
                        var filtered = {};
                        filtered[o.resultsProperty] = [];
                        filtered[o.totalProperty] = 0;
                        var index = 0;
                   
                        for (var i=0; i < data[o.resultsProperty].length; i++) {
                                if (o.matchBeginning) {
                                        if (data[o.resultsProperty][i].name.toLowerCase().indexOf(params.q.toLowerCase()) === 0) {
                                                filtered[o.resultsProperty][index++] = data[o.resultsProperty][i];
                                                filtered[o.totalProperty] += 1;
                                        }
                                } else {
                                        if (data[o.resultsProperty][i].name.toLowerCase().indexOf(params.q.toLowerCase()) != -1) {
                                                filtered[o.resultsProperty][index++] = data[o.resultsProperty][i];
                                                filtered[o.totalProperty] += 1;
                                        }
                                }
                        }
                        if (o.paging) {
                                var start = (params.p - 1) * params.s;
                                var howMany = (start + params.s) > filtered[o.totalProperty] ? filtered[o.totalProperty] - start : params.s;
                                filtered[o.resultsProperty] = filtered[o.resultsProperty].splice(start, howMany);
                        }
                        return filtered;
                }

 

I needed to be able to match the typed substring anywhere in the "option" name.

Nov 8, 2010 at 9:45 PM
Edited Nov 8, 2010 at 9:45 PM

Thanks for this suggestion. It helped me spot the filter function in flexbox.js file without having to spend much time. Making matchBeginning as a configurable parameter would be good.

I had to modify the function to filter based on first name, middle name or last name. Modified the for loop as below and it worked perfectly.

for (var i=0; i < data[o.resultsProperty].length; i++) {                          

   var names = data[o.resultsProperty][i].name.split(" ");                                                        

for(var j=0; j < names.length; j++) {                                                         

  if(names[j].toLowerCase().indexOf(params.q.toLowerCase()) === 0) {                            

filtered[o.resultsProperty][index++] = data[o.resultsProperty][i];                                        

filtered[o.totalProperty] += 1;                                        

break;                            

}                                                       

 }                                                

}

 

Nov 16, 2010 at 9:47 PM

A variation of your suggestion has been implemented in release 0.9.5 (the latest download).

Thank you for your idea!

Noah

From: atompkins77 [mailto:notifications@codeplex.com]
Sent: Tuesday, October 12, 2010 2:49 PM
To: Noah Heldman
Subject: Filter suggestion [flexbox:230645]

From: atompkins77

I would like to suggest adding a configuration option to allow matches to occur anywhere in the name text, rather than just at the beginning.

For example, given a config option called matchBeginning, modify the filter function like this:

function filter(data, params) {
var filtered = {};
filtered[o.resultsProperty] = [];
filtered[o.totalProperty] = 0;
var index = 0;

for (var i=0; i < data[o.resultsProperty].length; i++) {
if (o.matchBeginning) {
if (data[o.resultsProperty][i].name.toLowerCase().indexOf(params.q.toLowerCase()) === 0) {
filtered[o.resultsProperty][index++] = data[o.resultsProperty][i];
filtered[o.totalProperty] += 1;
}
} else {
if (data[o.resultsProperty][i].name.toLowerCase().indexOf(params.q.toLowerCase()) != -1) {
filtered[o.resultsProperty][index++] = data[o.resultsProperty][i];
filtered[o.totalProperty] += 1;
}
}
}
if (o.paging) {
var start = (params.p - 1) * params.s;
var howMany = (start + params.s) > filtered[o.totalProperty] ? filtered[o.totalProperty] - start : params.s;
filtered[o.resultsProperty] = filtered[o.resultsProperty].splice(start, howMany);
}
return filtered;
}

I needed to be able to match the typed substring anywhere in the "option" name.

Read the full discussion online.

To add a post to this discussion, reply to this email (flexbox@discussions.codeplex.com)

To start a new discussion for this project, email flexbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com