Skip to content
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

Open
j-braun0384 opened this issue Aug 13, 2018 · 2 comments
Open

multiple searchKeys would be stellar #564

j-braun0384 opened this issue Aug 13, 2018 · 2 comments

Comments

@j-braun0384
Copy link

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!

@fglueck
Copy link

fglueck commented Aug 5, 2020

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

@fglueck
Copy link

fglueck commented Aug 5, 2020

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;
          });
        }
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants