Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
if (changes) {
// re-init cache.
if (!this.igxForOf) {
return;
this.igxForOf = [];
}
this._updateSizeCache();
this._zone.run(() => {
Expand Down Expand Up @@ -1451,7 +1451,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
this.onDataChanging.emit(args);
// re-init cache.
if (!this.igxForOf) {
return;
this.igxForOf = [];
}
/* we need to reset the master dir if all rows are removed
(e.g. because of filtering); if all columns are hidden, rows are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ describe('IgxGrid Component Tests', () => {
}
});

it('should remove all rows if data becomes null/undefined.', async () => {
const fix = TestBed.createComponent(IgxGridRemoteVirtualizationComponent);
fix.detectChanges();
const grid = fix.componentInstance.instance;
expect(grid.rowList.length).toEqual(10);

fix.componentInstance.nullData();
fix.detectChanges();

const noRecordsSpan = fix.debugElement.query(By.css('.igx-grid__tbody-message'));
expect(grid.rowList.length).toEqual(0);
expect(noRecordsSpan).toBeTruthy();
expect(noRecordsSpan.nativeElement.innerText).toBe('Grid has no data.');
});

it('height/width should be calculated depending on number of records', fakeAsync(() => {
const fix = TestBed.createComponent(IgxGridTestComponent);
fix.componentInstance.grid.height = null;
Expand Down Expand Up @@ -4424,6 +4439,10 @@ export class LocalService {
this.records = this._records.asObservable();
}

nullData() {
this._records.next(null);
}

public getData(data?: IForOfState, cb?: (any) => void): any {
const size = data.chunkSize === 0 ? 10 : data.chunkSize;
this.dataStore = this.generateData(data.startIndex, data.startIndex + size);
Expand Down Expand Up @@ -4461,6 +4480,10 @@ export class IgxGridRemoteVirtualizationComponent implements OnInit, AfterViewIn
this.data = this.localService.records;
}

nullData() {
this.localService.nullData();
}

public ngAfterViewInit() {
this.localService.getData(this.instance.virtualizationState, (count) => {
this.instance.totalItemCount = count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
</igx-grid>

<button (click)="loadData()">loadData</button>
<button (click)="loadNullData()">null Data</button>
<button (click)="loadUndefinedData()">undefined Data</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,24 @@ export class GridVirtualizationSampleComponent implements OnInit, AfterViewInit

public loadData() {
this.grid.shouldGenerate = true;
this.remoteService.getData(this.grid.virtualizationState, (data) => {
this.remoteData = this.remoteService.remoteData;
});
}

public loadNullData() {
this.remoteService.nullData();
this.remoteData = this.remoteService.remoteData;
}

public loadUndefinedData() {
this.remoteService.undefinedData();
this.remoteData = this.remoteService.remoteData;
}

public ngAfterViewInit() {
this.remoteService.getData(this.grid.virtualizationState, (data) => {
this.grid.totalItemCount = data['@odata.count'];
});
this.remoteService.nullData();
this.remoteData = this.remoteService.remoteData;
}

dataLoading(evt) {
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/remote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export class RemoteService {
this.remoteData = this._remoteData.asObservable();
}

nullData() {
this._remoteData.next(null);
}

undefinedData() {
this._remoteData.next(undefined);
}

getData(data?: any, cb?: (any) => void) {
const dataState = data;
return this.http.get(this.buildUrl(dataState)).pipe(
Expand Down