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(grid): Fix calculate height when initially grid has no data #3950 #3970

Merged
merged 7 commits into from
Feb 28, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems to be getting out of control. Consider refactoring it in a method, or simplifying it.

return;
}
if (!this.nativeElement.parentNode || !this.nativeElement.parentNode.clientHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,26 +271,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