Skip to content

Commit 8f47a90

Browse files
committed
fix(pivotGrid): Set pivot date dimension locale data to avoid performance drops.
1 parent 634487e commit 8f47a90

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export class IgxPivotDateDimension implements IPivotDimension {
106106
public childLevel?: IPivotDimension;
107107
/** @hidden @internal */
108108
public memberName = 'AllPeriods';
109+
/** @hidden @internal */
110+
public locale?: string;
109111
public displayName: string;
110112
private _resourceStrings: IGridResourceStrings = null;
111113
private _baseDimension: IPivotDimension;
@@ -145,7 +147,7 @@ export class IgxPivotDateDimension implements IPivotDimension {
145147
memberFunction: (rec) => {
146148
const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
147149
const dateValue = recordValue ? getDateFormatter().createDateFromValue(recordValue) : null;
148-
return recordValue ? getDateFormatter().formatDateTime(dateValue, undefined, { month: 'long'}) : rec['Months'];
150+
return recordValue ? getDateFormatter().formatDateTime(dateValue, this.locale, { month: 'long'}) : rec['Months'];
149151
},
150152
enabled: true,
151153
childLevel: baseDimension

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
299299
this._pivotConfiguration = value;
300300
this.emitInitEvents(this._pivotConfiguration);
301301
this.filteringExpressionsTree = PivotUtil.buildExpressionTree(value);
302+
this.setDateDimensionsLocaleData();
302303
if (!this._init) {
303304
this.setupColumns();
304305
}
@@ -995,6 +996,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
995996
this.setupColumns();
996997
// Bind to onResourceChange after the columns have initialized the first time to avoid premature initialization.
997998
onResourceChangeHandle(this.destroy$, () => {
999+
this.setDateDimensionsLocaleData();
9981000
// Since the columns are kinda static, due to assigning DisplayName on init, they need to be regenerated.
9991001
this.setupColumns();
10001002
}, this);
@@ -2487,6 +2489,35 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
24872489

24882490
protected trackHorizontalRowGroup = (_index: number, rowGroup: IPivotGridRecord[]) => rowGroup[0]?.dataIndex;
24892491

2492+
/**
2493+
* Sets the locale and resourceStrings data based on the grid's properties for all IgxPivotDateDimensions in the config.
2494+
*/
2495+
protected setDateDimensionsLocaleData() {
2496+
const topDimensions = [...this.columnDimensions, ...this.rowDimensions];
2497+
for (const dim of topDimensions) {
2498+
let foundDateDim: IgxPivotDateDimension | undefined;
2499+
if (dim instanceof IgxPivotDateDimension) {
2500+
foundDateDim = dim;
2501+
} else if (dim.childLevel) {
2502+
var curChild: IPivotDimension | undefined = dim.childLevel;
2503+
while(curChild) {
2504+
if (curChild instanceof IgxPivotDateDimension) {
2505+
foundDateDim = curChild;
2506+
break;
2507+
}
2508+
curChild = curChild.childLevel;
2509+
}
2510+
}
2511+
2512+
if (foundDateDim) {
2513+
foundDateDim.resourceStrings = this.resourceStrings;
2514+
if (this.locale) {
2515+
foundDateDim.locale = this.locale;
2516+
}
2517+
}
2518+
}
2519+
}
2520+
24902521
/**
24912522
* @hidden @internal
24922523
*/

0 commit comments

Comments
 (0)