Skip to content

Commit

Permalink
fix(grid): recalculate grid body size when changing allowFiltering dy…
Browse files Browse the repository at this point in the history
…namically (#3320)

* fix(grid): recalculate grid body when changing allowFiltering dynamically #3290

* fix(grid): address review comments #3290
  • Loading branch information
SAndreeva authored and rkaraivanov committed Dec 6, 2018
1 parent 2134b22 commit 256ff23
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
13 changes: 12 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 @@ -66,6 +66,7 @@ import { IGridResourceStrings } from '../core/i18n/grid-resources';
import { CurrentResourceStrings } from '../core/i18n/resources';

const MINIMUM_COLUMN_WIDTH = 136;
const FILTER_ROW_HEIGHT = 50;

export const IgxGridTransaction = new InjectionToken<string>('IgxGridTransaction');

Expand Down Expand Up @@ -745,8 +746,18 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
set allowFiltering(value) {
if (this._allowFiltering !== value) {
this._allowFiltering = value;

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

this.filteringService.isFilterRowVisible = false;
this.filteringService.filteredColumn = null;

this.filteringService.registerSVGIcons();
if (this.gridAPI.get(this.id)) {
this.markForCheck();
Expand Down Expand Up @@ -3456,7 +3467,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 ? FILTER_ROW_HEIGHT : 0) + 1}px`;
}

if (!this._height) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ describe('IgxGrid - Column Moving', () => {
UIInteractions.simulatePointerEvent('pointerdown', header, 250, 65);
await wait();
UIInteractions.simulatePointerEvent('pointermove', header, 244, 71);
await wait();
await wait(50);
UIInteractions.simulatePointerEvent('pointermove', header, 100, 71);
await wait();
await wait(50);
UIInteractions.simulatePointerEvent('pointerup', header, 100, 71);
await wait();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,48 @@ describe('IgxGrid - Filtering Row UI actions', () => {
});
}));

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);
}));

it('Should remove FilterRow, when allowFiltering is set to false.', fakeAsync(() => {
const fix = TestBed.createComponent(IgxGridFilteringComponent);
const grid = fix.componentInstance.grid;
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 256ff23

Please sign in to comment.