Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filtering more than one value with ngx-filter-pipe angular

I'm using ngx-filter-pipe with angular 4 and I'm stuck with this issue. I managed to filter with one value and now im trying to filter data with more than one value: Here's what I got This is my component:

@Component({
  selector: 'deudas-list',
  templateUrl: '../views/deudas-list.html',
  providers: [ DeudaService ]
})
export class DeudasListComponent{
  public titulo: string;
  public  deudas: Deuda[];
  public  userFilter: any = { mes: '' };

  constructor(
      private _route: ActivatedRoute,
      private _router: Router,
      private _productoService: DeudaService
  ) {
    this.titulo = 'Listado de Pagos:';
  }

  ngOnInit() {
    this._productoService.getDeudas().subscribe(
      result =>{
          console.log(result['Cuotas'].Cuota);
          this.deudas = result['Cuotas'].Cuota;
      },
      error => {
        console.log(<any>error);
      }
    );
  }
}

This is my view

<div class="form-group has-feedback">
  <label for="term" class="sr-only">Search</label>
  <input type="text" name="term" [(ngModel)]="userFilter.mes" class="form-control" id="term" placeholder="Buscar por mes...">
  <span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
<div *ngIf="deudas" class="table-responsive col-lg-12 tablilla">
  <table class="table table-bordered table-striped table-responsive">
    <tbody>
      <tr *ngFor="let deuda of deudas | filterBy: userFilter | paginate: {itemsPerPage:10,currentPage: p}">
        <td>{{deuda.nombre_edificio}}</td>
        <td>{{deuda.numero_dpto}}</td>
        <td>{{deuda.Annio}}</td>
        <td>{{deuda.mes}}</td>
        <td>{{deuda.nombre_tipo_cuota}}</td>
        <td>{{deuda.monto_cuota}}</td>
        <td>{{deuda.nombre_estado_cuota}}</td>
        <td>{{deuda.fecha_pago}}</td>
      </tr>
    </tbody>
  </table>
  <pagination-controls (pageChange)="p = $event" class="paginador"></pagination-controls>
</div>

I tried multiple things but I cant make it work Here's the documentation I'm following https://github.com/VadimDez/ngx-filter-pipe I cant get $or filter to work as shown enter image description here

This is the data I'm getting from a ws

enter image description here

as you can see im using mes to filter but i'd like to use more than one <input type="text" name="term" [(ngModel)]="userFilter.mes" class="form-control" id="term" placeholder="Buscar por mes...">

any help would be appreciated.

like image 850
Rildo Gomez Avatar asked Sep 18 '17 23:09

Rildo Gomez


1 Answers

if you are using same data type for filtering a value you can do it in same filter but if you want different result you can use if else conditions or switch condition for different result as your requirements

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
    name: 'CurrencyFilter',
    pure: false
})
export class CurrencyFilterPipe implements PipeTransform {
    transform(items: number): any {
        var OrigionalValue = items;
        var franctionCount = parseInt(abp.session.crNoOfDgtsAftrDecimal);
        var value = items.toFixed(franctionCount);
        var commaSaperatedVal = value.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + abp.session.crDgtGrpSymbol + "");
       var selectedSymbol = abp.session.crCurrencySymbol;
        var selectedSymbol = "";
      var PosCurrFormat = abp.session.crPositivCurrencyFrmt;
        var NgtvCurrFormat = abp.session.crNagativeCurrencyFrmt;
        var FinalValue;
        if (items > 0)
        {
            switch (PosCurrFormat) {
                case "$1.1":
                    FinalValue = selectedSymbol + commaSaperatedVal;
                    break;
                case "1.1$":
                    FinalValue = commaSaperatedVal + selectedSymbol ;
                    break;
                case "$ 1.1":
                    FinalValue = selectedSymbol+" "+ commaSaperatedVal;
                    break;
                case "1.1 $":
                    FinalValue = commaSaperatedVal + " " + selectedSymbol;
                    break;
            }
            return FinalValue
        }
        if (items < 0) {
             commaSaperatedVal = commaSaperatedVal.replace('-','')
            switch (NgtvCurrFormat) {
                case "($1.1)": FinalValue = "("+selectedSymbol + commaSaperatedVal+")"; break;
                case "-$1.1": FinalValue = "-"+selectedSymbol + commaSaperatedVal; break;
                case "$-1.1": FinalValue = selectedSymbol + "-"+ commaSaperatedVal; break;
                case "$1.1-": FinalValue = selectedSymbol + commaSaperatedVal + "-" ; break;
                case "(1.1$)": FinalValue = "(" + commaSaperatedVal + selectedSymbol + ")"; break;
                case "-1.1$": FinalValue = "-" + commaSaperatedVal + selectedSymbol; break;
                case "1.1-$": FinalValue = commaSaperatedVal + "-"+ selectedSymbol ; break;
                case "1.1$-": FinalValue = commaSaperatedVal+selectedSymbol + "-"; break;
                case "-1.1 $": FinalValue = "-" + commaSaperatedVal +" "+ selectedSymbol ; break;
                case "-$ 1.1": FinalValue = "-" + " "+ selectedSymbol + commaSaperatedVal; break;
                case "1.1 $-": FinalValue = commaSaperatedVal + " " + selectedSymbol  + "-"; break;
                case "$ 1.1-": FinalValue = selectedSymbol + " " + commaSaperatedVal + "-"; break;
                case "$ -1.1": FinalValue = selectedSymbol + " " + "-" + commaSaperatedVal; break;
                case "1.1- $": FinalValue = commaSaperatedVal + "-" + " " + selectedSymbol; break;
                case "($ 1.1)": FinalValue = "(" + selectedSymbol + " " + commaSaperatedVal + ")"; break;
                case "(1.1 $)": FinalValue = "(" + commaSaperatedVal +" "+ selectedSymbol + ")"; break;
            }
            return FinalValue
        }
        return FinalValue;
    }
}
like image 75
Manoj Meria Avatar answered Oct 08 '22 15:10

Manoj Meria