You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common requirement for a filterBy search in ... is to specify multiple keys to look, but not all of them (as that might produce false positives from fields irrelevant/invisible to the user).
Below is a crude modification of filterBy, dubbed filterByKeys. Usage example:
<liv-repeat="users | filterByKeys searchText in 'firstname' 'lastname'">{{username}}</li>
Would it be possible to add this filter to the core (or perhaps replace filterBy with it, as it should be backwards compatible)?
Currently, keeping this in a separate custom filters file requires duplicating the contains function and pulling in the same requirements as for array-filters.js itself.
varfilterByKeys=function(){// Convert arguments to an actual Arrayvarargs=[].slice.call(arguments)vararr=args.shift()varsearch=args.shift()// cast to lowercase stringsearch=(''+search).toLowerCase()// strip optional 'in'if(args[0]=='in'){deleteargs[0]}// if left with 0 keys, fall back to all keysvarkeys=args.length>0 ? args : Object.keys(args);// filter input arrayreturnarr.filter(function(item){varresult=falsekeys.forEach(function(datakey){result=result||contains(Path.get(item,datakey),search)})returnresult;})}
PS. Possible issues might arise from the arguments conversion as that is a bit funky and I'm not 100% sure of browser compatibility
The text was updated successfully, but these errors were encountered:
A common requirement for a
filterBy search in ...
is to specify multiple keys to look, but not all of them (as that might produce false positives from fields irrelevant/invisible to the user).Below is a crude modification of
filterBy
, dubbedfilterByKeys
. Usage example:Would it be possible to add this filter to the core (or perhaps replace
filterBy
with it, as it should be backwards compatible)?Currently, keeping this in a separate custom filters file requires duplicating the
contains
function and pulling in the same requirements as forarray-filters.js
itself.PS. Possible issues might arise from the
arguments
conversion as that is a bit funky and I'm not 100% sure of browser compatibilityThe text was updated successfully, but these errors were encountered: