Skip to content

Commit

Permalink
fix(grid): recalculate grid body when changing allowFiltering dynamic…
Browse files Browse the repository at this point in the history
…ally #3290

# Conflicts:
#	projects/igniteui-angular/src/lib/grids/grid-base.component.ts
#	projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts
  • Loading branch information
SAndreeva committed Dec 5, 2018
1 parent c6a0e6d commit c7f0d43
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
15 changes: 14 additions & 1 deletion projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this._allowFiltering = value;
this.filteringService.isFilterRowVisible = false;
this.filteringService.filteredColumn = null;

this.calcHeight += value ? -this.defaultFilterRowHeight : this.defaultFilterRowHeight;
if (this._ngAfterViewInitPaassed) {
if (this.maxLevelHeaderDepth) {
this.theadRow.nativeElement.style.height = `${(this.maxLevelHeaderDepth + 1) * this.defaultRowHeight +
(value ? this.defaultFilterRowHeight : 0) + 1}px`;
}
}

this.filteringService.registerSVGIcons();
if (this.gridAPI.get(this.id)) {
this.markForCheck();
Expand Down Expand Up @@ -2379,6 +2388,10 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
}
}

get defaultFilterRowHeight(): number {
return 50;
}

/**
* Returns the maximum width of the container for the pinned `IgxColumnComponent`s.
* ```typescript
Expand Down Expand Up @@ -3456,7 +3469,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
// TODO: Calculate based on grid density
if (this.maxLevelHeaderDepth) {
this.theadRow.nativeElement.style.height = `${(this.maxLevelHeaderDepth + 1) * this.defaultRowHeight +
(this.allowFiltering ? this._rowHeight : 0) + 1}px`;
(this.allowFiltering ? this.defaultFilterRowHeight : 0) + 1}px`;
}

if (!this._height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,48 @@ describe('IgxGrid - Filtering Row UI actions', () => {
filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
expect(filteringRow).toBeNull();
}));

it('Should size grid correctly if enable/disable filtering in run time.', fakeAsync(() => {
const fix = TestBed.createComponent(IgxGridFilteringComponent);
fix.detectChanges();

const grid = fix.componentInstance.grid;
const head = grid.nativeElement.querySelector('.igx-grid__thead');
const body = grid.nativeElement.querySelector('.igx-grid__tbody');

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);

fix.componentInstance.activateFiltering(false);
fix.detectChanges();

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);

fix.componentInstance.activateFiltering(true);
fix.detectChanges();

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);
}));

it('Should size grid correctly if enable/disable filtering in run time - MCH.', fakeAsync(() => {
const fix = TestBed.createComponent(IgxGridFilteringMCHComponent);
fix.detectChanges();

const grid = fix.componentInstance.grid;
const head = grid.nativeElement.querySelector('.igx-grid__thead');
const body = grid.nativeElement.querySelector('.igx-grid__tbody');

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);

fix.componentInstance.activateFiltering(false);
fix.detectChanges();

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);

fix.componentInstance.activateFiltering(true);
fix.detectChanges();

expect(head.getBoundingClientRect().bottom).toEqual(body.getBoundingClientRect().top);
}));
});

export class CustomFilter extends IgxFilteringOperand {
Expand Down Expand Up @@ -2822,6 +2864,11 @@ export class IgxGridFilteringComponent {
];

@ViewChild(IgxGridComponent) public grid: IgxGridComponent;

public activateFiltering(activate: boolean) {
this.grid.allowFiltering = activate;
this.grid.cdr.markForCheck();
}
}

@Component({
Expand Down Expand Up @@ -2858,7 +2905,15 @@ export class IgxGridFilteringScrollComponent extends IgxGridFilteringComponent {
</igx-column>
</igx-grid>`
})
export class IgxGridFilteringMCHComponent extends IgxGridFilteringComponent { }
export class IgxGridFilteringMCHComponent extends IgxGridFilteringComponent {

@ViewChild(IgxGridComponent) public grid: IgxGridComponent;

public activateFiltering(activate: boolean) {
this.grid.allowFiltering = activate;
this.grid.cdr.markForCheck();
}
}

const expectedResults = [];

Expand Down

0 comments on commit c7f0d43

Please sign in to comment.