On my system, I created a directive that gets the parameters needed to update a table, which would be:
function filtroAngularTable() {
return {
restrict: 'E',
scope: {
lista: '=',
config: '='
},
controller: 'PaginacaoCtrl',
templateUrl: 'app/diretivas/paginacao_at_table/html/filtro.html'
}
}
Through this information I can update the table based on what I type:
$scope.listaOriginal = $scope.lista;
$scope.listaFiltrada = $scope.listaOriginal;
$scope.atualizarTabelaComFiltro = function () {
$scope.listaFiltrada = $filter("filter")($scope.listaOriginal, {nome: $scope.filtro});
$scope.lista = $scope.listaFiltrada;
$scope.config.total = $scope.lista.length;
}
So far it works perfectly, it's filtering by title, getting the ng-model "$ scope.filter" from the input.
But the question is: How can I filter by another field, besides the title, with the same input?
For example, filter by first and last name using the same input.
I tried to put another object in the filter, tried to put another position in the object, but I did not succeed.
$scope.listaFiltrada = $filter("filter")($scope.listaOriginal, {nome: $scope.filtro}, {sobrenome: $scope.filtro});
$scope.listaFiltrada = $filter("filter")($scope.listaOriginal, {nome: $scope.filtro, sobrenome: $scope.filtro});
I also wanted to make the list of fields I want to filter be passed as a policy scope to be more dynamic.
I'm using the Samu / angular-table .
EDITION
I forgot to mention earlier, but the ng-model from where I shot what to filter is here:
<div class='ui icon input'>
<i class='search icon'></i>
<input placeholder='Pesquisar pelo título...' type='text' ng-model="filtro" ng-change="atualizarTabelaComFiltro()">
</div>
So, as I said, I'm using the Samu / angular-table . It just gets the parameters of where to take the items from the list and their configuration and does the rest basically alone, such as:
<table class="ui compact table" at-table at-paginated at-list="lista" at-config="config"></table>
I still can not see how I can create an external input to update the table based on dynamic filters.