Last active
August 29, 2015 14:08
-
-
Save tcdevs/c18d50e792c968b6d4f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| IMPORTANT: requires Lo-Dash (http://lodash.com/) or Underscore.js (http://underscorejs.org/) | |
| Usage: ng-repeat="item in items | fuzzyFilter:searchText" | |
| */ | |
| var app = angular.module('app', []); | |
| app.filter('fuzzyFilter', function () { | |
| return function (items, searchText) { | |
| var searchWords; | |
| if (searchText) { | |
| searchWords = searchText.split(' '); | |
| return _.filter(items, function (item) { | |
| var itemText = _.values(item).join(' ').toLowerCase(); | |
| return _.every(searchWords, function (searchWord) { | |
| return itemText.search(searchWord.toLowerCase()) !== -1; | |
| }); | |
| }); | |
| } else { | |
| return []; | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment