diff --git a/projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts b/projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts index 96efe72ff2a..a0ee52c9459 100644 --- a/projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts +++ b/projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts @@ -106,6 +106,8 @@ export class IgxPivotDateDimension implements IPivotDimension { public childLevel?: IPivotDimension; /** @hidden @internal */ public memberName = 'AllPeriods'; + /** @hidden @internal */ + public locale?: string; public displayName: string; private _resourceStrings: IGridResourceStrings = null; private _baseDimension: IPivotDimension; @@ -145,7 +147,7 @@ export class IgxPivotDateDimension implements IPivotDimension { memberFunction: (rec) => { const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec); const dateValue = recordValue ? getDateFormatter().createDateFromValue(recordValue) : null; - return recordValue ? getDateFormatter().formatDateTime(dateValue, undefined, { month: 'long'}) : rec['Months']; + return recordValue ? getDateFormatter().formatDateTime(dateValue, this.locale, { month: 'long'}) : rec['Months']; }, enabled: true, childLevel: baseDimension diff --git a/projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts b/projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts index aebbdbb6831..310cfd61468 100644 --- a/projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts +++ b/projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts @@ -299,6 +299,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni this._pivotConfiguration = value; this.emitInitEvents(this._pivotConfiguration); this.filteringExpressionsTree = PivotUtil.buildExpressionTree(value); + this.setDateDimensionsLocaleData(); if (!this._init) { this.setupColumns(); } @@ -995,6 +996,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni this.setupColumns(); // Bind to onResourceChange after the columns have initialized the first time to avoid premature initialization. onResourceChangeHandle(this.destroy$, () => { + this.setDateDimensionsLocaleData(); // Since the columns are kinda static, due to assigning DisplayName on init, they need to be regenerated. this.setupColumns(); }, this); @@ -1626,6 +1628,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni * This parameter is optional. If not set it will add it to the end of the collection. */ public insertDimensionAt(dimension: IPivotDimension, targetCollectionType: PivotDimensionType, index?: number) { + this.setDateDimensionsLocaleData([dimension]); const targetCollection = this.getDimensionsByType(targetCollectionType); if (index !== undefined) { targetCollection.splice(index, 0, dimension); @@ -2487,6 +2490,37 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni protected trackHorizontalRowGroup = (_index: number, rowGroup: IPivotGridRecord[]) => rowGroup[0]?.dataIndex; + /** + * Sets the locale and resourceStrings data based on the grid's properties for all IgxPivotDateDimensions in the config. + * By default search all dimensions (even not enabled). + * @param entryDimensions Entry dimension on which to check for IgxPivotDateDimension instead of the default. + */ + protected setDateDimensionsLocaleData(entryDimensions?: IPivotDimension[]) { + const topDimensions = entryDimensions ?? [...this.allDimensions]; + for (const dim of topDimensions) { + let foundDateDim: IgxPivotDateDimension | undefined; + if (dim instanceof IgxPivotDateDimension) { + foundDateDim = dim; + } else if (dim.childLevel) { + var curChild: IPivotDimension | undefined = dim.childLevel; + while(curChild) { + if (curChild instanceof IgxPivotDateDimension) { + foundDateDim = curChild; + break; + } + curChild = curChild.childLevel; + } + } + + if (foundDateDim) { + foundDateDim.resourceStrings = this.resourceStrings; + if (this.locale) { + foundDateDim.locale = this.locale; + } + } + } + } + /** * @hidden @internal */