I am developing a search page for an application. I have searched a lot at google, but I can't find anything than fragmented information about filters.
What I need is a list of checkboxes containing certain lists of elements (like in the example, languages). I had put a filter for ordering, for the name of the client, but I want to add filters to auxiliar tables like (as I said) languages.
Clients:
$scope.clientes = [
{ 'id': '3', 'name': 'Susana', 'surname': 'Rodríguez Torrón', 'languages': [{'id': 1, 'name': 'english'}, {'id': 2, 'name': 'spanish'}] },
{ 'id': '4', 'name': 'Pablo', 'surname': 'Campos Pérez', 'languages': [{'id': 3, 'name': 'german'}, {'id': 5, 'name': 'japanese'}] }
];
Languages:
$langs = [
{'id': 1, 'name': 'english' },
{'id': 2, 'name': 'spanish' },
{'id': 3, 'name': 'german' },
{'id': 4, 'name': 'japanese' }
];
HTML (for checkboxes list):
<div class="row">
<div class="col-md-12">
<h4>Languages</h4>
<div class="checkbox-block" ng-repeat="lang in langs">
<label class="checkbox" for="{{lang.id}}">
<input type="checkbox" ng-model="langs[lang.id]" name="languages_group" id="{{lang.id}}" />
<span ng-bind-html="lang.name"></span>
</label>
</div>
</div>
</div>;
Clients:
<div class="client-wrapper" ng-repeat="client in clients | orderBy:order_field:order_type | filter:query">
... all the data of every client showed here ...
</div>;
In the array $scope.langs
I havethe checks checked, now I want to compare it with every client and to show only the clients having that language(s). Can it be done? Can you help me to know how??
EDIT: Code of the filter.
app.filter('langsFilter', function () {
return function (input, $scope) {
var output = [];
to_langs = $scope.filters.langs;
var trueContro = false;
for (var lang in to_langs) {
if (to_langs[lang] === true) {
trueContro = true;
}
}
for (var client in input) {
for (var i = 0; i < input[client].langs.length; i++) {
if (trueContro === true) {
if (to_langs[client.langs[i]]) {
output.push(input[client]);
}
} else {
output.push(input[client]);
}
}
}
return output;
};
});
As you said I posted the code I am working at. It doesn't works right now, I know, but It will give you an idea of what I need to achieve:
We have a set of clients, in addition to another filters, this filter will compare the langs of every client for show only the client with those langs.