Skip to content

Commit d634233

Browse files
authored
Merge pull request #6009 from IgniteUI/nrobakova/fix-issue-5986
Check if grid data is undefined
2 parents f725b48 + eaa9f48 commit d634233

File tree

8 files changed

+38
-10
lines changed

8 files changed

+38
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class IgxGridTransactionPipe implements PipeTransform {
105105
transform(collection: any[], id: string, pipeTrigger: number) {
106106
const grid: IgxGridBaseComponent = this.gridAPI.grid;
107107

108-
if (collection && grid.transactions.enabled) {
108+
if ( grid.transactions.enabled) {
109109
const result = DataUtil.mergeTransactions(
110110
cloneArray(collection),
111111
grid.transactions.getAggregatedChanges(true),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('IgxGrid - Summaries #grid', () => {
185185
fixture.componentInstance.data = undefined;
186186
fixture.detectChanges();
187187

188-
expect(grid.data).toEqual(undefined);
188+
expect(grid.data).toEqual([]);
189189
expect(() => {
190190
grid.enableSummaries(idColumn.field);
191191
fixture.detectChanges();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
136136
}
137137

138138
public set data(value: any[]) {
139-
this._data = value;
139+
this._data = value || [];
140140
this.summaryService.clearSummaryCache();
141141
if (this.shouldGenerate) {
142142
this.setupColumns();

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

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseCompone
9191
*/
9292
@Input()
9393
public set data(value: any[]) {
94-
this._data = value;
94+
this._data = value || [];
9595
this.summaryService.clearSummaryCache();
9696
if (this.shouldGenerate) {
9797
this.setupColumns();

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
IgxTreeGridWrappedInContComponent,
1010
IgxTreeGridAutoGenerateComponent,
1111
IgxTreeGridDefaultLoadingComponent,
12-
IgxTreeGridCellSelectionComponent
12+
IgxTreeGridCellSelectionComponent,
13+
IgxTreeGridSummariesTransactionsComponent
1314
} from '../../test-utils/tree-grid-components.spec';
1415
import { wait } from '../../test-utils/ui-interactions.spec';
1516
import { GridSelectionMode } from '../common/enums';
@@ -26,7 +27,8 @@ describe('IgxTreeGrid Component Tests #tGrid', () => {
2627
IgxTreeGridWrappedInContComponent,
2728
IgxTreeGridAutoGenerateComponent,
2829
IgxTreeGridDefaultLoadingComponent,
29-
IgxTreeGridCellSelectionComponent
30+
IgxTreeGridCellSelectionComponent,
31+
IgxTreeGridSummariesTransactionsComponent
3032
],
3133
imports: [
3234
NoopAnimationsModule, IgxTreeGridModule]
@@ -205,4 +207,30 @@ describe('IgxTreeGrid Component Tests #tGrid', () => {
205207

206208
});
207209

210+
describe('Setting null data', () => {
211+
it('should not throw error when data is null', () => {
212+
let errorMessage = '';
213+
fix = TestBed.createComponent(IgxTreeGridCellSelectionComponent);
214+
fix.componentInstance.data = null;
215+
try {
216+
fix.detectChanges();
217+
} catch (ex) {
218+
errorMessage = ex.message;
219+
}
220+
expect(errorMessage).toBe('');
221+
});
222+
223+
it('should not throw error when data is null and transactions are enabled', () => {
224+
let errorMessage = '';
225+
fix = TestBed.createComponent(IgxTreeGridSummariesTransactionsComponent);
226+
fix.componentInstance.data = null;
227+
try {
228+
fix.detectChanges();
229+
} catch (ex) {
230+
errorMessage = ex.message;
231+
}
232+
expect(errorMessage).toBe('');
233+
});
234+
});
235+
208236
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent implements IGridD
102102
}
103103

104104
public set data(value: any[]) {
105-
this._data = value;
105+
this._data = value || [];
106106
this.summaryService.clearSummaryCache();
107107
if (this.shouldGenerate) {
108108
this.setupColumns();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ export class IgxTreeGridTransactionPipe implements PipeTransform {
273273

274274
transform(collection: any[], id: string, pipeTrigger: number): any[] {
275275
const grid: IgxTreeGridComponent = this.gridAPI.grid;
276-
if (collection && grid.transactions.enabled) {
276+
277+
if (grid.transactions.enabled) {
277278
const aggregatedChanges = grid.transactions.getAggregatedChanges(true);
278279
if (aggregatedChanges.length > 0) {
279280
const primaryKey = grid.primaryKey;
@@ -300,7 +301,6 @@ export class IgxTreeGridTransactionPipe implements PipeTransform {
300301
}
301302
}
302303
}
303-
304304
return collection;
305305
}
306306
}

0 commit comments

Comments
 (0)