Skip to content

Commit bd4d87c

Browse files
authored
Merge pull request #8443 from IgniteUI/sstoychev/loading-filtering-rework-101
fix(grid): loading not showing in empty filtered grids #8279 - 10.1
2 parents 86c5f83 + 764a103 commit bd4d87c

File tree

6 files changed

+64
-56
lines changed

6 files changed

+64
-56
lines changed

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
443443

444444
public get_all_data(includeTransactions = false): any[] {
445445
const grid = this.grid;
446-
let data = grid.data ? grid.data : [];
446+
let data = grid && grid.data ? grid.data : [];
447447
data = includeTransactions ? grid.dataWithAddedInTransactionRows : data;
448448
return data;
449449
}

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6486,6 +6486,37 @@ 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+
if (this.isLoading && (this.hasZeroResultFilter || this.hasNoData)) {
6494+
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
6495+
}
6496+
6497+
if (this.hasZeroResultFilter) {
6498+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
6499+
}
6500+
6501+
if (this.hasNoData) {
6502+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
6503+
}
6504+
}
6505+
6506+
/**
6507+
* @hidden @internal
6508+
*/
6509+
private get hasZeroResultFilter(): boolean {
6510+
return this.filteredData && this.filteredData.length === 0;
6511+
}
6512+
6513+
/**
6514+
* @hidden @internal
6515+
*/
6516+
private get hasNoData(): boolean {
6517+
return !this.data || this.dataLength === 0;
6518+
}
6519+
64896520
/**
64906521
* @hidden @internal
64916522
*/
@@ -6524,7 +6555,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65246555
* @hidden @internal
65256556
*/
65266557
get shouldOverlayLoading(): boolean {
6527-
return this.isLoading && this.data && this.data.length > 0;
6558+
return this.isLoading && !this.hasNoData && !this.hasZeroResultFilter;
65286559
}
65296560

65306561
/**

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { IgxTabsModule, IgxTabsComponent } from '../../tabs/public_api';
2424
import { GridSelectionMode } from '../common/enums';
2525
import { registerLocaleData } from '@angular/common';
2626
import localeDE from '@angular/common/locales/de';
27+
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
28+
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
2729

2830
describe('IgxGrid Component Tests #grid', () => {
2931
const MIN_COL_WIDTH = '136px';
@@ -346,7 +348,7 @@ describe('IgxGrid Component Tests #grid', () => {
346348
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
347349
fixture.detectChanges();
348350
tick(100);
349-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
351+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
350352
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);
351353

352354
// Clear filter and check if grid's body height is restored based on all loaded rows
@@ -398,7 +400,7 @@ describe('IgxGrid Component Tests #grid', () => {
398400
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
399401
fixture.detectChanges();
400402
tick(100);
401-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
403+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
402404

403405
// Clear filter and check if grid's body height is restored based on all loaded rows
404406
grid.clearFilter(columns[0].field);
@@ -482,6 +484,33 @@ describe('IgxGrid Component Tests #grid', () => {
482484
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(500);
483485
}));
484486

487+
it('should render loading indicator when loading is enabled and the grid has empty filtering pre-applied', fakeAsync(() => {
488+
const fixture = TestBed.createComponent(IgxGridTestComponent);
489+
const grid = fixture.componentInstance.grid;
490+
grid.filteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
491+
grid.filteringExpressionsTree.filteringOperands = [
492+
{
493+
condition: IgxNumberFilteringOperand.instance().condition('equals'),
494+
fieldName: 'index',
495+
searchVal: 0
496+
}
497+
];
498+
grid.isLoading = true;
499+
fixture.detectChanges();
500+
tick(16);
501+
502+
const gridBody = fixture.debugElement.query(By.css(TBODY_CLASS));
503+
const loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
504+
const domGrid = fixture.debugElement.query(By.css('igx-grid')).nativeElement;
505+
506+
// make sure default width/height are applied when there is no data
507+
expect(domGrid.style.height).toBe('100%');
508+
expect(domGrid.style.width).toBe('100%');
509+
510+
expect(loadingIndicator).not.toBeNull();
511+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
512+
}));
513+
485514
it('should allow applying custom loading indicator', fakeAsync(() => {
486515
const fixture = TestBed.createComponent(IgxGridRemoteOnDemandComponent);
487516
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)