Skip to content

Commit

Permalink
fix(module:table): fix table th filter style (#1300)
Browse files Browse the repository at this point in the history
close #1238
  • Loading branch information
vthinkxie committed Apr 11, 2018
1 parent 0552141 commit 29c559a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions components/table/nz-th.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface NzThItemInterface {
</span>
</div>
<nz-dropdown nzTrigger="click" *ngIf="nzShowFilter" [nzClickHide]="false" [hasFilterButton]="true" (nzVisibleChange)="dropDownVisibleChange($event)">
<i class="anticon anticon-filter" [class.ant-table-filter-selected]="filterVisible" nz-dropdown></i>
<i class="anticon anticon-filter" [class.ant-table-filter-selected]="hasFilterValue" nz-dropdown></i>
<ul nz-menu>
<ng-container *ngIf="nzFilterMultiple">
<li nz-menu-item *ngFor="let filter of multipleFilterList" (click)="checkMultiple(filter)">
Expand Down Expand Up @@ -106,7 +106,7 @@ export class NzThComponent {
private _showCheckbox = false;
private _showRowSelection = false;
el: HTMLElement;
filterVisible = false;
hasFilterValue = false;
multipleFilterList: NzThItemInterface[] = [];
singleFilterList: NzThItemInterface[] = [];
/* tslint:disable-next-line:no-any */
Expand Down Expand Up @@ -228,10 +228,14 @@ export class NzThComponent {

search(): void {
if (this.nzFilterMultiple) {
this.nzFilterChange.emit(this.multipleFilterList.filter(item => item.checked).map(item => item.value));
const filterList = this.multipleFilterList.filter(item => item.checked).map(item => item.value);
this.hasFilterValue = filterList.length > 0;
this.nzFilterChange.emit(filterList);
} else {
const checkedFilter = this.singleFilterList.find(item => item.checked);
this.nzFilterChange.emit(checkedFilter ? checkedFilter.value : null);
const filterValue = checkedFilter ? checkedFilter.value : null;
this.hasFilterValue = isNotNil(filterValue);
this.nzFilterChange.emit(filterValue);
}
this.hideDropDown();
}
Expand All @@ -241,6 +245,7 @@ export class NzThComponent {
this.initSingleFilterList();
this.search();
this.hideDropDown();
this.hasFilterValue = false;
}

checkMultiple(filter: NzThItemInterface): void {
Expand All @@ -257,7 +262,6 @@ export class NzThComponent {
}

dropDownVisibleChange(value: boolean): void {
this.filterVisible = value;
if (!value) {
this.search();
}
Expand Down
3 changes: 3 additions & 0 deletions components/table/nz-th.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ describe('nz-th', () => {
testComponent.nzThComponent.checkMultiple(testComponent.nzThComponent.multipleFilterList[ 0 ]);
testComponent.nzThComponent.dropDownVisibleChange(false);
fixture.detectChanges();
expect(testComponent.nzThComponent.hasFilterValue).toBe(true);
expect(testComponent.filterChange).toHaveBeenCalledWith([ '1' ]);
});
it('should reset work', () => {
Expand All @@ -190,6 +191,7 @@ describe('nz-th', () => {
testComponent.nzThComponent.reset();
fixture.detectChanges();
expect(testComponent.filterChange).toHaveBeenCalledWith([]);
expect(testComponent.nzThComponent.hasFilterValue).toBe(false);
});
it('should filterMultiple work', () => {
testComponent.showFilter = true;
Expand All @@ -202,6 +204,7 @@ describe('nz-th', () => {
testComponent.nzThComponent.dropDownVisibleChange(false);
fixture.detectChanges();
expect(testComponent.filterChange).toHaveBeenCalledWith('1');
expect(testComponent.nzThComponent.hasFilterValue).toBe(true);
});
it('should expand work', () => {
fixture.detectChanges();
Expand Down

0 comments on commit 29c559a

Please sign in to comment.