Filter combobox search Angularjs

Asked

Viewed 400 times

0

I have the SELECT multiple with options for query, only when selecting an item does not return anything, if someone can give a strength I thank you.

inserir a descrição da imagem aqui

/* Retorna operadoras */
$scope.operadoras = [{
    nome: "CLARO"
  },
  {
    nome: "TIM"
  },
  {
    nome: "VIVO"
  },
  {
    nome: "OI"
  },
  {
    nome: "NEXTEL"
  }
];

$scope.filtroOperadora = function() {
  return ($scope.operadoras == busca.nome);
}
<div class="form-group col-md-2 input-group-sm mb-3">
  <label for="exampleInputPassword1" class="text-sm font-weight-bold">Operadora</label>
  <select class="form-control seleciona text-sm" multiple name="prospectOperadora" data-width="100%" ng-model="busca">
    <option value="">Selecione</option>
    <option ng-repeat="oper in operadoras" value="{{oper.nome}}">
      {{oper.nome}}
    </option>
  </select>
</div>

<li style="font-size: 13px; padding:10px;" ng-repeat="prospect in listaProspect | orderBy: 'prospectNome' | betweenDate:'prospeccaoPrevisao':startDate:endDate | filter:busca track by $index">
</li>

  • Is there any way to put the entire angular code into your question? this represents your minimum example is it gets complicated us to make the code that surely already exists!

2 answers

1

I decided to create an example, where the grouping of information is made a filter in the SELECT with the property multiple:

var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
  $scope.operadora = [];
  $scope.operadoras = [{
      nome: "CLARO"
    },
    {
      nome: "TIM"
    },
    {
      nome: "VIVO"
    },
    {
      nome: "OI"
    },
    {
      nome: "NEXTEL"
    }
  ];

  $scope.lista = [{
      nome: 'item 1',
      operadora: 'OI'
    },
    {
      nome: 'item 2',
      operadora: 'OI'
    },
    {
      nome: 'item 3',
      operadora: 'CLARO'
    },
    {
      nome: 'item 4',
      operadora: 'NEXTEL'
    },
    {
      nome: 'item 5',
      operadora: 'VIVO'
    },
    {
      nome: 'item 6',
      operadora: 'TIM'
    }
  ];

  $scope.listFilter = function(model) {    
    if ($scope.operadora.length == 0) return true;
    return $scope.operadora.indexOf(model.operadora) > -1;
  };
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"></script>

<div ng-app="app" ng-controller="ctrl">
  <select multiple ng-model="operadora" class="selectpicker">
    <option ng-repeat="o in operadoras" value="{{o.nome}}">{{o.nome}}</option>
  </select>
  <br /><br /><br />
  <ul>
    <li ng-repeat="i in lista  | filter:listFilter">
      {{i.nome}} {{i.operadora}}
    </li>
  </ul>
</div>

In that case you need to create a custom filter, and search the array of information the items that were selected in the SELECT which is another array also.

References:

0


By the code informed, it is not possible to conclude much.

But for what you put here:

$scope.filtroOperadora = function() {
  return ($scope.operadoras == busca.nome);
}

It doesn’t make much sense, since the $Scope.operators is an Array and name search. is probably a string.

I made a basic example here: https://next.plnkr.co/edit/Q1pKm1iN0P102c23

However, as you can probably have an array of strings you want to search inside the list of operators, goes another example: https://next.plnkr.co/edit/LoV5i3g6byeERHWo

Abs.

  • Thanks @Allan for the tip but that’s not really what I’m trying to do, but anyway thank you and I’ll try here! That now beyond this doubt others have arisen, but in order for me to apprehend I have to suffer, rsrsrsrsr

Browser other questions tagged

You are not signed in. Login or sign up in order to post.