fix(pivot-grid): fix pivot grid localization#17246
Conversation
…format
When IgxPivotDateDimension is used with fullDate enabled and no
custom memberFunction, attach a locale-aware formatter that formats
leaf-level date values using {dateStyle: 'short'} via Intl.DateTimeFormat.
The formatter is added to a new optional IPivotDimension.formatter
property and applied in the row dimension rendering layer only,
so data keys, sorting, and filtering are unaffected.
Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/0e38c414-30cb-4920-a7ea-3bc9882a866b
Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/0e38c414-30cb-4920-a7ea-3bc9882a866b Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
…assertion Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/0e38c414-30cb-4920-a7ea-3bc9882a866b Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
|
@copilot Fix the failing tests |
The failing test is unrelated to this PR's changes. The failure is in This is a timing-sensitive virtual scrolling test in the
None of those files are in the |
There was a problem hiding this comment.
Pull request overview
This PR adds a display-only formatting hook for pivot dimensions and uses it to localize leaf-level fullDate values produced by IgxPivotDateDimension, so row headers show locale-aware short dates instead of raw ISO strings.
Changes:
- Added optional
formattertoIPivotDimensionfor display-only header formatting. - Wrapped the
fullDateleaf dimension inIgxPivotDateDimensionwith a locale-aware short-date formatter (when no custommemberFunctionis provided). - Applied
dim.formatterwhen extracting row dimension header text and updated a related spec assertion to be locale-independent.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| projects/igniteui-angular/grids/pivot-grid/src/pivot-row-dimension-content.component.ts | Applies IPivotDimension.formatter to row header text before creating the header column. |
| projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.spec.ts | Updates expected leaf date header assertion to use Intl.DateTimeFormat output. |
| projects/igniteui-angular/grids/core/src/pivot-grid.interface.ts | Introduces formatter?: (value) => ... to IPivotDimension with docs. |
| projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts | Adds default localized formatter for fullDate leaf dimension when no custom memberFunction exists. |
|
@copilot Fix the comments |
… date parsing Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/fc2cee95-07d2-43e3-873c-8aafce84bc93 Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
…escing Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/fc2cee95-07d2-43e3-873c-8aafce84bc93 Co-authored-by: Hristo313 <57346540+Hristo313@users.noreply.github.com>
All four review comments addressed in commits
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts:112
IgxPivotDateDimensiondeclarespublic locale?: string;twice (lines 110 and 118), which will fail TypeScript compilation with a duplicate identifier/property error. Keep a singlelocaleproperty (with the new JSDoc) and remove the duplicate.
public locale?: string;
public displayName: string;
/**
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts:2389
- PR description says locale/resource changes now call
notifyDimensionChange(true)(to regenerate columns and synchronously bumppipeTrigger+detectChanges()), but the currentonResourceChangeHandlecallback inngAfterContentInitstill callssetupColumns()directly (seepivot-grid.component.ts:998-1002). That mismatch likely means dimension headers can still update a cycle late after locale changes.
ref.instance.header = dim?.headerFormatter != null ? (dim.headerFormatter(rawHeader, dim, undefined) ?? rawHeader) : rawHeader;
ref.instance.field = key;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts:1002
notifyDimensionChange(true)callssetupColumns()(which triggersautogenerateColumns()and already incrementspipeTrigger) and then incrementspipeTriggeragain. In this onResourceChange callback (outside Angular zone) you mainly need to regenerate columns and rundetectChanges()synchronously; callingsetupColumns()+cdr.detectChanges()avoids the redundantpipeTriggerincrement while keeping the immediate UI update.
onResourceChangeHandle(this.destroy$, () => {
this.setDateDimensionsLocaleData();
// Use notifyDimensionChange to also increment pipeTrigger and run detectChanges synchronously,
// since this callback fires outside Angular's zone and markForCheck() alone is not enough.
this.notifyDimensionChange(true);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.ts:2390
- The PR description says locale/resource changes now call
notifyDimensionChange(true)sopipeTrigger++andcdr.detectChanges()run immediately (avoiding the “one cycle behind” header update). However, the current implementation still callssetupColumns()directly inside theonResourceChangeHandlecallback (seepivot-grid.component.ts:998-1002), andnotifyDimensionChange(pivot-grid.component.ts:1035-1041) is not used. If the intent is to fix immediate header refresh on locale change, the resource-change handler should be updated accordingly.
const parentPath = parent != null ? parent.field + this.pivotKeys.columnDimensionSeparator : null;
const rawHeader = parentPath != null && key.startsWith(parentPath) ? key.substring(parentPath.length) : key;
const dim = value.dimension as IPivotDimension;
ref.instance.header = dim?.headerFormatter != null ? (dim.headerFormatter(rawHeader, dim, undefined) ?? rawHeader) : rawHeader;
ref.instance.field = key;
Adds a display-only
headerFormatterhook toIPivotDimensionand uses it to localize the leaf-levelfullDatevalues produced byIgxPivotDateDimension, so both row and column dimension headers show locale-aware short dates instead of raw ISO strings. Also fixes date dimension headers being one cycle behind after a locale change.Changes Made
IPivotDimension.headerFormatter— new optional callback(value: any, dimension?, rowData?) => string | null | undefinedfor display-only dimension header formatting; returningnull/undefinedfalls back to the raw value. Annotated withcsTreatAsEvent+blazorOnlyScriptfor Blazor/C# interop consistency.IgxPivotDateDimension— attaches a locale-aware{ dateStyle: 'short' }formatter to thefullDateleaf dimension when no custommemberFunctionis provided. All date dimension levels (Months, Quarters, Years, fullDate) now use a consistentrecordValue != null && recordValue !== ''guard instead of truthy checks, so epoch-0 timestamps are handled correctly.pivot-row-dimension-content.component.ts— appliesdim.headerFormatter(rawHeader) ?? rawHeaderwhen building row dimension header columns.pivot-grid.component.ts— appliesdim.headerFormatter(rawHeader) ?? rawHeaderincreateColumnForDimensionso column dimension headers are also formatted. Raw header extraction usesparent.fieldinstead ofparent.headerfor stable value extraction regardless of whether a parent column has a formatter. Fixed theonResourceChangeHandlecallback to usenotifyDimensionChange(true)instead ofsetupColumns(), which additionally incrementspipeTriggerand callscdr.detectChanges()synchronously so dimension headers update immediately when the locale changes (the callback fires outside Angular's zone, makingmarkForCheck()alone insufficient).pivot-grid.spec.ts— updated leaf date header assertion to useIntl.DateTimeFormatlocale-aware output and replaced ambiguousnew Date('12/08/2021')with unambiguousnew Date(2021, 11, 8).CHANGELOG.md— added entry documenting the newIPivotDimension.headerFormatterproperty and the locale update fix.Notes
headerFormatterapplies consistently to both row and column dimension header text; returningnull/undefinedfalls back to the raw value.detectChanges()call.