Skip to content

Commit

Permalink
fix(grid): Fix calculate height when initially grid has no data #3950
Browse files Browse the repository at this point in the history
  • Loading branch information
mpavlinov committed Feb 21, 2019
1 parent 7e773dd commit 5cd81aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* Sets this._height
*/
protected _derivePossibleHeight() {
if ((this._height && this._height.indexOf('%') === -1) || !this._height || !this.isAttachedToDom) {
if ((this._height && this._height.indexOf('%') === -1) || !this._height || !this.isAttachedToDom || this.rowBasedHeight === 0) {
return;
}
if (!this.nativeElement.parentNode || !this.nativeElement.parentNode.clientHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,31 @@ describe('IgxGrid Component Tests', () => {

const grid = fixture.componentInstance.grid;
const gridBody = fixture.debugElement.query(By.css(TBODY_CLASS));
const domGrid = fixture.debugElement.query(By.css('igx-grid')).nativeElement;

// make sure default width/height are applied when there is no data
expect(domGrid.style.height).toBe('100%');
expect(domGrid.style.width).toBe('100%');

// Check for loaded rows in grid's container
fixture.componentInstance.generateData(30);
fixture.detectChanges();
tick(1000);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(1000);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);

// Check for empty filter grid message and body less than 100px
const columns = fixture.componentInstance.grid.columns;
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
fixture.detectChanges();
tick(100);
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeLessThan(100);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);

// Clear filter and check if grid's body height is restored based on all loaded rows
grid.clearFilter(columns[0].field);
fixture.detectChanges();
tick(100);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(1000);
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);

// Clearing grid's data and check for empty grid message
fixture.componentInstance.clearData();
Expand Down

0 comments on commit 5cd81aa

Please sign in to comment.