Skip to content

Commit b337e9f

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

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
@@ -6413,6 +6413,26 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
64136413
return this.transactions.enabled ? this.dataWithAddedInTransactionRows.length : this.gridAPI.get_all_data().length;
64146414
}
64156415

6416+
/**
6417+
* @hidden @internal
6418+
*/
6419+
public get template(): TemplateRef<any> {
6420+
const hasZeroResultFilter = this.filteredData && this.filteredData.length === 0;
6421+
const hasNoData = !this.data || this.dataLength === 0;
6422+
6423+
if (this.isLoading && (hasZeroResultFilter || hasNoData)) {
6424+
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
6425+
}
6426+
6427+
if (hasZeroResultFilter) {
6428+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
6429+
}
6430+
6431+
if (hasNoData) {
6432+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
6433+
}
6434+
}
6435+
64166436
/**
64176437
* @hidden @internal
64186438
*/

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
@@ -481,6 +481,26 @@ describe('IgxGrid Component Tests #grid', () => {
481481
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(500);
482482
}));
483483

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

813-
814-
/**
815-
* @hidden @internal
816-
*/
817-
public get template(): TemplateRef<any> {
818-
if (this.filteredData && this.filteredData.length === 0) {
819-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
820-
}
821-
822-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
823-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
824-
}
825-
826-
if (this.dataLength === 0) {
827-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
828-
}
829-
}
830-
831813
/**
832814
* @hidden @internal
833815
*/

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
@@ -444,23 +444,6 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
444444
});
445445
}
446446

447-
/**
448-
* @hidden
449-
*/
450-
public get template(): TemplateRef<any> {
451-
if (this.filteredData && this.filteredData.length === 0) {
452-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
453-
}
454-
455-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
456-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
457-
}
458-
459-
if (this.dataLength === 0) {
460-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
461-
}
462-
}
463-
464447
/**
465448
* @hidden
466449
*/

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
@@ -630,23 +630,6 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
630630
return this.extractDataFromSelection(source, formatters, headers);
631631
}
632632

633-
/**
634-
* @hidden
635-
*/
636-
public get template(): TemplateRef<any> {
637-
if (this.filteredData && this.filteredData.length === 0) {
638-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
639-
}
640-
641-
if (this.isLoading && (!this.data || this.dataLength === 0)) {
642-
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
643-
}
644-
645-
if (this.dataLength === 0) {
646-
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
647-
}
648-
}
649-
650633
protected writeToData(rowIndex: number, value: any) {
651634
mergeObjects(this.flatData[rowIndex], value);
652635
}

0 commit comments

Comments
 (0)