Skip to content

Instantly share code, notes, and snippets.

@AlexanderArmua
Created March 28, 2016 20:22
Show Gist options
  • Save AlexanderArmua/5616c710c709ca718ab7 to your computer and use it in GitHub Desktop.
Save AlexanderArmua/5616c710c709ca718ab7 to your computer and use it in GitHub Desktop.
Revisa una variable y si contiene texto, busca en todos los campos que se le diga en un array y si encuentra coincidencia retorna true para mostrarlo en el filtro. (v1)
var filters=["filtro1","filtro2","filtro3","filtro4","filtroN"];
$scope.filtrar=function(object)
{
if($scope.filtroTxT.length)
{
for (var i = 0; i<filters.length; i++)
{
if((object[filters[i]]) && (object[filters[i]]==$scope.filtroTxT))//Revisa cada campo dentro del array y lo busca dentro del objeto.
{
return true;
}
}
return false;
}
else
{
return true;
}
};
<input type="text" placeholder="Filter..." ng-model="filtroTxT"/>
<table>
<thead>
<tr>
<th>Filtro 1</th>
<th>Filtro 2</th>
<th>Filtro 3</th>
<th>Filtro 4</th>
<th>Filtro N</th>
</tr>
</thead>
<tbody ng-repeat="object in QUERYDB">
<tr>{{object.filtro1}}</tr>
<tr>{{object.filtro2}}</tr>
<tr>{{object.filtro3}}</tr>
<tr>{{object.filtro4}}</tr>
<tr>{{object.filtroN}}</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment