I am trying to make the following functionality work in my code:
- Searching for Carpenter Company should return 2 records
- Searching for "Carpenter Company" (with quotes) should return 1 record
So far, I have not been successful in getting it to work. I also attempted to use regex with the expression:
"[\w\s]+\"
You can find a sample of my code on Plunker here:
http://plnkr.co/edit/SqFOqqiRG7oFXHY89o6e?p=preview
I am specifically focusing on this part of the code:
var app = angular.module('filter', [])
app.controller('MainController', function($scope) {
$scope.deals = [{
lob: 'Marine, Motor, Carpenter',
cedent: 'ABC Paris Company',
treaty: 'QS - Test'
}, {
lob: 'Liability',
cedent: 'Carpenter Company',
treaty: 'W/XL Test'
}];
});
// filterBy implementation
app.filter('filterBy', function() {
return function(array, query) {
var parts = query && query.trim().split(/\s+/g) ,
keys = Object.keys(array[0]);
if (!parts || !parts.length) return array;
return array.filter(function(obj) {
return parts.every(function(part) {
return keys.some(function(key) {
return String(obj[key]).toLowerCase().indexOf(part.toLowerCase()) > -1;
});
});
});
};
});
Any hints or suggestions on how to solve this issue would be greatly appreciated. Thank you!