Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 55ce7f0

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
fix an issue where grid options were copied over on route change, that caused weird behaviors in next grid
1 parent 94df9c2 commit 55ce7f0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'slickgrid/plugins/slick.headermenu';
2020
import 'slickgrid/plugins/slick.rowmovemanager';
2121
import 'slickgrid/plugins/slick.rowselectionmodel';
2222
import { AfterViewInit, Component, EventEmitter , Injectable, Input, Output, OnInit } from '@angular/core';
23-
import { castToPromise } from './../services/utilities';
23+
import { castToPromise, immutableMerge } from './../services/utilities';
2424
import { GlobalGridOptions } from './../global-grid-options';
2525
import { CellArgs, Column, FormElementType, GridOption } from './../models';
2626
import { ControlAndPluginService, FilterService, GridEventService, SortService, ResizerService } from './../services';
@@ -179,7 +179,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnInit {
179179
if (this.gridOptions.enableFiltering) {
180180
this.gridOptions.showHeaderRow = true;
181181
}
182-
const options = { ...GlobalGridOptions, ...this.gridOptions };
182+
// use an immutable merge to avoid changing properties in GlobalGridOptions when changing route
183+
const options = immutableMerge(GlobalGridOptions, this.gridOptions);
183184
return options;
184185
}
185186

src/app/modules/angular-slickgrid/services/utilities.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'rxjs/add/operator/take';
55
import 'rxjs/add/operator/toPromise';
66
import * as moment_ from 'moment-mini';
77
const moment: any = (<any>moment_).default || moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
8+
import _ from 'lodash';
89

910
/**
1011
* Try casting an input of type Promise | Observable into a Promise type.
@@ -228,3 +229,17 @@ export function parseUtcDate(inputDateString: string, useUtc: boolean): string |
228229

229230
return date;
230231
}
232+
233+
export function immutableMerge(...args) {
234+
if (args.length === 0) {
235+
return {};
236+
}
237+
if (args.length === 1) {
238+
return args[0];
239+
}
240+
if (args.length === 2) {
241+
return _.merge(_.cloneDeep(args[0]), args[1]);
242+
} else {
243+
return immutableMerge(_.first(args), immutableMerge(_.rest(args)));
244+
}
245+
}

0 commit comments

Comments
 (0)