Skip to content

Commit fc462c9

Browse files
authored
Merge branch '9.1.x' into astaev/issue8388-9.1.x
2 parents 5a4826b + b5a358c commit fc462c9

File tree

6 files changed

+64
-57
lines changed

6 files changed

+64
-57
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
@@ -6413,6 +6413,37 @@ 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+
if (this.isLoading && (this.hasZeroResultFilter || this.hasNoData)) {
6421+
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
6422+
}
6423+
6424+
if (this.hasZeroResultFilter) {
6425+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
6426+
}
6427+
6428+
if (this.hasNoData) {
6429+
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
6430+
}
6431+
}
6432+
6433+
/**
6434+
* @hidden @internal
6435+
*/
6436+
private get hasZeroResultFilter(): boolean {
6437+
return this.filteredData && this.filteredData.length === 0;
6438+
}
6439+
6440+
/**
6441+
* @hidden @internal
6442+
*/
6443+
private get hasNoData(): boolean {
6444+
return !this.data || this.dataLength === 0;
6445+
}
6446+
64166447
/**
64176448
* @hidden @internal
64186449
*/
@@ -6451,7 +6482,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
64516482
* @hidden @internal
64526483
*/
64536484
get shouldOverlayLoading(): boolean {
6454-
return this.isLoading && this.data && this.data.length > 0;
6485+
return this.isLoading && !this.hasNoData && !this.hasZeroResultFilter;
64556486
}
64566487

64576488
/**

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { SortingDirection, ISortingExpression } from '../../data-operations/sort
2222
import { configureTestSuite } from '../../test-utils/configure-suite';
2323
import { IgxTabsModule, IgxTabsComponent } from '../../tabs/public_api';
2424
import { GridSelectionMode } from '../common/enums';
25-
25+
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
26+
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
2627

2728
describe('IgxGrid Component Tests #grid', () => {
2829
const MIN_COL_WIDTH = '136px';
@@ -345,7 +346,7 @@ describe('IgxGrid Component Tests #grid', () => {
345346
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
346347
fixture.detectChanges();
347348
tick(100);
348-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
349+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
349350
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);
350351

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

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

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