Как отфильтровать данные, используя параметры снимка - PullRequest
1 голос
/ 30 июня 2019

Я пытаюсь отфильтровать таблицу данных с параметрами, полученными из URL. мне удалось получить параметры, но я не вижу способа отфильтровать таблицу, используя их. Я хочу, чтобы это было сделано автоматически, поскольку пользователь выбрал их на первой странице, а с другой стороны он получает отфильтрованную таблицу.

Это мой текущий пример HTML-таблицы (это только часть таблицы):

<mat-table [dataSource]="dataSource"  [hidden]="!show" matSort >
  <!-- Location  -->
  <ng-container matColumnDef="AITOR">
    <mat-header-cell *matHeaderCellDef> Location </mat-header-cell>
    <mat-cell *matCellDef="let container"> {{container.AITOR}} </mat-cell>
  </ng-container>

Это мой ток Компонент:

  filterCheckboxes: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);

  constructor(private marinService:MarinServiceService,private route: ActivatedRoute) { }

  ngOnInit() {
    this.marinService.getAllContainers().subscribe((result) => {
     //Data
      this.dataSource = new MatTableDataSource(result);
      //Paginator
      this.dataSource.paginator = this.paginator;
      //AutoFilter Form 1st page
      const clientType : string = this.route.snapshot.queryParamMap.get('clientType');
      const storageType : any = this.route.snapshot.queryParamMap.get('storageTypes');
      console.log('The Client name is : '+clientType+'  '+'The storage Facility is : '+storageType);
      //CheckBox Filter
      this.dataSource.filterPredicate = (data: Container, filter: any) => {
        return filter.split(',').every((item: any) => data.SOG_MCOLH.indexOf(item) !== -1);
      };

      this.filterCheckboxes.subscribe((newFilterValue: any[]) => {
        this.dataSource.filter = newFilterValue.join(',');
      });

    });
  }



  toggle(){
    this.show = !this.show;

    if(this.show) {
      this.tableHide = "Hide";
    } else {
      this.tableHide = "Show";
    }
  }

  applyFilter(filterValue: string) {
    this.dataSource.filter = filterValue.trim().toLowerCase();
  }

  public getRowsValue(flag) {
    if (flag === null) {
      return this.dataSource.length;
    } else {
      return this.dataSource.filter(i => (i.state == flag)).length;
    }
  }

  addFilter(change: MatCheckboxChange) {
    if (this.filterCheckboxes.value.some((a: any) => a === change.source.value)) {
      this.filterCheckboxes.next(this.filterCheckboxes.value.filter((a: any) => a !== change.source.value));
    } else {
      this.filterCheckboxes.next(this.filterCheckboxes.value.concat(change.source.value));
    }
  }
}

Я пытался смотреть онлайн, но на самом деле не нашел ничего, что говорит об этом.

У меня есть Pipe, который используется для фильтра флажка.

...