Skip to content

Commit 0721fe9

Browse files
committed
refactor(pivotGrid): Replace use of Intl with new locale and fix columns not updated on locale change.
1 parent 4d80504 commit 0721fe9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-dimensions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GridColumnDataType } from '../../data-operations/data-util';
55
import { IPivotDimension } from './pivot-grid.interface';
66
import { PivotUtil } from './pivot-util';
77
import { onResourceChangeHandle } from '../../core/utils';
8+
import { getI18nManager } from 'igniteui-i18n-core';
89

910
export interface IPivotDateDimensionOptions {
1011
/** Enables/Disables total value of all periods. */
@@ -114,7 +115,6 @@ export class IgxPivotDateDimension implements IPivotDimension {
114115
private _defaultResourceStrings = getCurrentResourceStrings(GridResourceStringsEN);
115116
private _baseDimension: IPivotDimension;
116117
private _options: IPivotDateDimensionOptions = {};
117-
private _monthIntl = new Intl.DateTimeFormat('default', { month: 'long' });
118118
private _destroyRef = inject(DestroyRef);
119119

120120

@@ -154,7 +154,8 @@ export class IgxPivotDateDimension implements IPivotDimension {
154154
memberName: 'Months',
155155
memberFunction: (rec) => {
156156
const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
157-
return recordValue ? this._monthIntl.format(new Date(recordValue)) : rec['Months'];
157+
const dateValue = recordValue ? getI18nManager().createDateFromValue(recordValue) : null;
158+
return recordValue ? getI18nManager().formatDateTime(dateValue, undefined, { month: 'long'}) : rec['Months'];
158159
},
159160
enabled: true,
160161
childLevel: baseDimension
@@ -165,7 +166,8 @@ export class IgxPivotDateDimension implements IPivotDimension {
165166
memberName: 'Quarters',
166167
memberFunction: (rec) => {
167168
const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
168-
return recordValue ? `Q` + Math.ceil((new Date(recordValue).getMonth() + 1) / 3) : rec['Quarters'];
169+
const dateValue = recordValue ? getI18nManager().createDateFromValue(recordValue) : null;
170+
return recordValue ? `Q` + Math.ceil((dateValue.getMonth() + 1) / 3) : rec['Quarters'];
169171
},
170172
enabled: true,
171173
childLevel: monthDimension
@@ -176,7 +178,8 @@ export class IgxPivotDateDimension implements IPivotDimension {
176178
memberName: 'Years',
177179
memberFunction: (rec) => {
178180
const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
179-
return recordValue ? (new Date(recordValue)).getFullYear().toString() : rec['Years'];
181+
const dateValue = recordValue ? getI18nManager().createDateFromValue(recordValue) : null;
182+
return recordValue ? dateValue.getFullYear().toString() : rec['Years'];
180183
},
181184
enabled: true,
182185
childLevel: quarterDimension

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { IgxGridExcelStyleFilteringComponent, IgxExcelStyleColumnOperationsTempl
7070
import { IgxPivotGridNavigationService } from './pivot-grid-navigation.service';
7171
import { IgxPivotColumnResizingService } from '../resizing/pivot-grid/pivot-resizing.service';
7272
import { IgxFlatTransactionFactory, IgxOverlayService, State, Transaction, TransactionService } from '../../services/public_api';
73-
import { cloneArray, PlatformUtil, resizeObservable } from '../../core/utils';
73+
import { cloneArray, onResourceChangeHandle, PlatformUtil, resizeObservable } from '../../core/utils';
7474
import { IgxPivotFilteringService } from './pivot-filtering.service';
7575
import { DataUtil, GridColumnDataType } from '../../data-operations/data-util';
7676
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
@@ -1060,6 +1060,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10601060
localeId,
10611061
platform,
10621062
_diTransactions);
1063+
onResourceChangeHandle(this.destroy$, () => {
1064+
// Since the columns are kinda static, due to assigning DisplayName on init, they need to be regenerated.
1065+
this.setupColumns();
1066+
}, this);
10631067
}
10641068

10651069
/**

0 commit comments

Comments
 (0)