Skip to content

Commit a30a065

Browse files
committed
fix(grid): loading not showing in empty filtered grids #8279
1 parent f1e8a80 commit a30a065

File tree

5 files changed

+40
-52
lines changed

5 files changed

+40
-52
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,6 +6486,26 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
64866486
return this.transactions.enabled ? this.dataWithAddedInTransactionRows.length : this.gridAPI.get_all_data().length;
64876487
}
64886488

6489+
/**
6490+
* @hidden @internal
6491+
*/
6492+
public get template(): TemplateRef<any> {
6493+
const hasZeroResultFilter = this.filteredData && this.filteredData.length === 0;
6494+
const hasNoData = !this.data || this.dataLength === 0;
6495+
6496+
if (this.isLoading && (hasZeroResultFilter || hasNoData)) {
6497+
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
6498+
}
6499+
6500+
if (hasZeroResultFilter) {
6501+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
6502+
}
6503+
6504+
if (hasNoData) {
6505+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
6506+
}
6507+
}
6508+
64896509
/**
64906510
* @hidden @internal
64916511
*/

projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,26 @@ describe('IgxGrid Component Tests #grid', () => {
482482
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(500);
483483
}));
484484

485+
fit('should render loading indicator when loading is enabled and the grid has empty filtering pre-applied', fakeAsync(() => {
486+
const fixture = TestBed.createComponent(IgxGridTestComponent);
487+
const grid = fixture.componentInstance.grid;
488+
grid.filter('index', 0, IgxNumberFilteringOperand.instance().condition('equals'), true);
489+
grid.isLoading = true;
490+
fixture.detectChanges();
491+
tick(16);
492+
493+
const gridBody = fixture.debugElement.query(By.css(TBODY_CLASS));
494+
let loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
495+
const domGrid = fixture.debugElement.query(By.css('igx-grid')).nativeElement;
496+
497+
// make sure default width/height are applied when there is no data
498+
expect(domGrid.style.height).toBe('100%');
499+
expect(domGrid.style.width).toBe('100%');
500+
501+
expect(loadingIndicator).not.toBeNull();
502+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
503+
}));
504+
485505
it('should allow applying custom loading indicator', fakeAsync(() => {
486506
const fixture = TestBed.createComponent(IgxGridRemoteOnDemandComponent);
487507
fixture.componentInstance.instance.loadingGridTemplate = fixture.componentInstance.customTemaplate;

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -829,24 +829,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
829829
}
830830
}
831831

832-
833-
/**
834-
* @hidden @internal
835-
*/
836-
public get template(): TemplateRef<any> {
837-
if (this.filteredData && this.filteredData.length === 0) {
838-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
839-
}
840-
841-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
842-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
843-
}
844-
845-
if (this.dataLength === 0) {
846-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
847-
}
848-
}
849-
850832
/**
851833
* @hidden @internal
852834
*/

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,23 +469,6 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
469469
});
470470
}
471471

472-
/**
473-
* @hidden
474-
*/
475-
public get template(): TemplateRef<any> {
476-
if (this.filteredData && this.filteredData.length === 0) {
477-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
478-
}
479-
480-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
481-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
482-
}
483-
484-
if (this.dataLength === 0) {
485-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
486-
}
487-
}
488-
489472
/**
490473
* @hidden
491474
*/

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -651,23 +651,6 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
651651
return this.extractDataFromSelection(source, formatters, headers);
652652
}
653653

654-
/**
655-
* @hidden
656-
*/
657-
public get template(): TemplateRef<any> {
658-
if (this.filteredData && this.filteredData.length === 0) {
659-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
660-
}
661-
662-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
663-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
664-
}
665-
666-
if (this.dataLength === 0) {
667-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
668-
}
669-
}
670-
671654
protected writeToData(rowIndex: number, value: any) {
672655
mergeObjects(this.flatData[rowIndex], value);
673656
}

0 commit comments

Comments
 (0)