At.js icon indicating copy to clipboard operation
At.js copied to clipboard

multiple searchKeys would be stellar

Open j-braun0384 opened this issue 7 years ago • 2 comments

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!

j-braun0384 avatar Aug 13 '18 07:08 j-braun0384

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 avatar Aug 05 '20 09:08 fglueck

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


fglueck avatar Aug 05 '20 15:08 fglueck