-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple searchKeys would be stellar #564
Comments
I have the same Problem, I use it für User selection. I have the name xyyyyy and a description xxxxx yyyyyy. If I create a extra search field with both I have more then the double data in the json object and it is only neaded for searching in two values. searchKey: ['name', 'otherfield'] should be a nice feature for that case |
I try to do this, but I think the searchkey definition will made trouble on other functions: searchKey: ["d", 'n'],
limit: 12,
callbacks: {
filter: function(query, data, searchKey) {
var i, item, len, slen,_results = [];
if(!Array.isArray(searchKey))
searchKey = [searchKey];
slen = searchKey.length;
query = query.toLowerCase();
for (i = 0, len = data.length; i < len; i++) {
item = data[i];
for (j = 0 ; j < slen; j++) {
if (item[searchKey[j]].toString().toLowerCase().indexOf(query)>-1) {
_results.push(item);
}
}
}
return _results;
},
sorter: function(query, items, searchKey) {
var _results = [], i, item, len;
if (!query) {
return items;
}
if(!Array.isArray(searchKey))
searchKey = [searchKey];
slen = searchKey.length;
query = query.toLowerCase();
for (i = 0, len = items.length; i < len; i++) {
item = items[i];
for (j = 0 ; j < slen; j++) {
item.atwho_order = new String(item[searchKey[j]]).toLowerCase().indexOf(query);
if (item.atwho_order > -1) {
_results.push(item);
}
}
}
return _results.sort(function(a, b) {
return a.atwho_order - b.atwho_order;
});
}
}
|
This lib is absolutely rock solid, however, being able to check against multiple searchKeys would make it in my opinion bulletproof. Thats the one implementation missing. With the current behaviour, if an object contains multiple keys with matching values ( like a username or name ), it only checks against one and fails if a match isn't found for the specified searchKey even if the other value has a match. Multiple searchKeys would remedy this!
The text was updated successfully, but these errors were encountered: