Skip to content

Commit

Permalink
fix(module:table): fix table filter (#6384) (#6385)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 authored Feb 13, 2021
1 parent ef3af58 commit ad01c8f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions components/table/src/addon/filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { arraysEqual } from 'ng-zorro-antd/core/util';
import { NzI18nService, NzTableI18nInterface } from 'ng-zorro-antd/i18n';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
Expand Down Expand Up @@ -75,17 +76,16 @@ export class NzTableFilterComponent implements OnChanges, OnDestroy, OnInit {
@Output() readonly filterChange = new EventEmitter<NzSafeAny[] | NzSafeAny>();
private destroy$ = new Subject();
locale!: NzTableI18nInterface;
isChanged = false;
isChecked = false;
isVisible = false;
listOfParsedFilter: NzThItemInterface[] = [];
listOfChecked: NzSafeAny[] = [];

trackByValue(_: number, item: NzThItemInterface): NzSafeAny {
return item.value;
}

check(filter: NzThItemInterface): void {
this.isChanged = true;
if (this.filterMultiple) {
this.listOfParsedFilter = this.listOfParsedFilter.map(item => {
if (item === filter) {
Expand All @@ -109,7 +109,6 @@ export class NzTableFilterComponent implements OnChanges, OnDestroy, OnInit {
}

reset(): void {
this.isChanged = true;
this.isVisible = false;
this.listOfParsedFilter = this.parseListOfFilter(this.listOfFilter, true);
this.isChecked = this.getCheckedStatus(this.listOfParsedFilter);
Expand All @@ -120,18 +119,19 @@ export class NzTableFilterComponent implements OnChanges, OnDestroy, OnInit {
this.isVisible = value;
if (!value) {
this.emitFilterData();
} else {
this.listOfChecked = this.listOfParsedFilter.filter(item => item.checked).map(item => item.value);
}
}

emitFilterData(): void {
if (this.isChanged) {
const listOfChecked = this.listOfParsedFilter.filter(item => item.checked).map(item => item.value);
const listOfChecked = this.listOfParsedFilter.filter(item => item.checked).map(item => item.value);
if (!arraysEqual(this.listOfChecked, listOfChecked)) {
if (this.filterMultiple) {
this.filterChange.emit(listOfChecked);
} else {
this.filterChange.emit(listOfChecked.length > 0 ? listOfChecked[0] : null);
}
this.isChanged = false;
}
}

Expand Down

0 comments on commit ad01c8f

Please sign in to comment.