Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
Angularjs - Filter one column with multiple option select input

Im trying to filter a single column using a select with multiple options. As soon as I select more than 2 options, the filter breaks and return me 0 results when I am expecting to return the options I selected.

Example if I select Apple and Grape, I should see all items that match my options.

Here an example of my data:

$scope.products = [
    {name:"Apple",type:"fruit"},
    {name:"Grape",type:"fruit"},
    {name:"Orage",type:"fruit"},
    {name:"Carrot",type:"vegetable"},
    {name:"Milk",type:"dairy"}
]

Here is my HTML

<div ng-controller="MyCtrl">
    <select multiple ng-model="Search_by_name">
     <option value="Apple">Apple</option>
      <option value="Grape">Grape</option>
       <option value="Orage">Orage</option>
        <option value="Carrot">Carrot</option>
         <option value="Milk">Milk</option>
    </select>
    <ul>
        <li ng-repeat="item in products | filter:{name: Search_by_name }">{{item.name}}</li>
    </ul>
</div>

http://jsfiddle.net/gvmp6jr9/

Ive been searching google for 2 hours now and cant keep to wrap my head around this one. Anyone have any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can create a custom filter function in controller :

$scope.multipleFilter = function(filterCriteria) {
  return function(item) {
    return (!filterCriteria || filterCriteria.indexOf(item.name) > -1 );
  }
};

In the html you can use it like that

<li ng-repeat="item in products | filter: multipleFilter(Search_by_name)">{{item.name}}</li>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda