Skip to content

Commit 0d766cb

Browse files
committed
fix(grid): check if data is defined in the pagingPipe #5949
1 parent 53603b6 commit 0d766cb

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { async, TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { IgxGridModule } from './index';
4-
import { ReorderedColumnsComponent, PagingAndEditingComponent, GridIDNameJobTitleComponent } from '../../test-utils/grid-samples.spec';
4+
import {
5+
ReorderedColumnsComponent,
6+
PagingAndEditingComponent,
7+
GridIDNameJobTitleComponent,
8+
GridWithUndefinedDataComponent
9+
} from '../../test-utils/grid-samples.spec';
510
import { PagingComponent } from '../../test-utils/grid-base-components.spec';
611
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
712
import { IgxGridComponent } from './grid.component';
@@ -21,7 +26,8 @@ describe('IgxGrid - Grid Paging', () => {
2126
ReorderedColumnsComponent,
2227
PagingComponent,
2328
PagingAndEditingComponent,
24-
GridIDNameJobTitleComponent
29+
GridIDNameJobTitleComponent,
30+
GridWithUndefinedDataComponent
2531
],
2632
imports: [IgxGridModule, NoopAnimationsModule]
2733
}).compileComponents();
@@ -63,7 +69,7 @@ describe('IgxGrid - Grid Paging', () => {
6369
verifyGridPager(fix, 3, '1', '1 of 4', [true, true, false, false]);
6470
}));
6571

66-
it('should paginate data API', fakeAsync (() => {
72+
it('should paginate data API', fakeAsync(() => {
6773
const fix = TestBed.createComponent(PagingComponent);
6874
fix.detectChanges();
6975

@@ -281,7 +287,7 @@ describe('IgxGrid - Grid Paging', () => {
281287
verifyGridPager(fix, 2, '9', '3 of 3', []);
282288
});
283289

284-
it('activate/deactivate paging', fakeAsync(() => {
290+
it('activate/deactivate paging', fakeAsync(() => {
285291
const fix = TestBed.createComponent(ReorderedColumnsComponent);
286292
const grid = fix.componentInstance.grid;
287293
fix.detectChanges();
@@ -461,6 +467,27 @@ describe('IgxGrid - Grid Paging', () => {
461467
expect(gridElement.querySelector(PAGER_CLASS)).not.toBeNull();
462468
}));
463469

470+
it('should not throw error when data is undefined', fakeAsync(() => {
471+
let errorMessage = '';
472+
const fix = TestBed.createComponent(GridWithUndefinedDataComponent);
473+
try {
474+
fix.detectChanges();
475+
} catch (ex) {
476+
errorMessage = ex.message;
477+
}
478+
expect(errorMessage).toBe('');
479+
const grid = fix.componentInstance.grid;
480+
let paginator = grid.nativeElement.querySelector(PAGER_CLASS);
481+
expect(paginator).toBeNull();
482+
expect(grid.rowList.length).toBe(0);
483+
tick(305);
484+
fix.detectChanges();
485+
486+
paginator = grid.nativeElement.querySelector(PAGER_CLASS);
487+
expect(paginator).toBeDefined();
488+
expect(grid.rowList.length).toBe(11);
489+
}));
490+
464491
function verifyGridPager(fix, rowsCount, firstCellValue, pagerText, buttonsVisibility) {
465492
const disabled = 'igx-button--disabled';
466493
const grid = fix.componentInstance.grid;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class IgxGridPagingPipe implements PipeTransform {
104104
index: page,
105105
recordsPerPage: perPage
106106
};
107-
DataUtil.correctPagingState(state, collection.data.length);
107+
DataUtil.correctPagingState(state, collection.data ? collection.data.length : 0);
108108

109109
const result = {
110110
data: DataUtil.page(cloneArray(collection.data), state),

0 commit comments

Comments
 (0)