Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:table): fix table th filter style #1300

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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