Skip to content

fix(pivot-grid): fix date format based on the localization#17256

Open
Hristo313 wants to merge 4 commits into21.2.xfrom
hhristov/fix-pivot-grid-date-localization-21.2.x
Open

fix(pivot-grid): fix date format based on the localization#17256
Hristo313 wants to merge 4 commits into21.2.xfrom
hhristov/fix-pivot-grid-date-localization-21.2.x

Conversation

@Hristo313
Copy link
Copy Markdown
Contributor

@Hristo313 Hristo313 commented Apr 30, 2026

Closes #16442

Description

Adds a display-only formatter hook to IPivotDimension and uses it to localize the leaf-level fullDate values produced by IgxPivotDateDimension, so both row and column dimension headers show locale-aware short dates instead of raw ISO strings.

Motivation / Context

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

Test Configuration:

  • Angular version:
  • Browser(s):
  • OS:

Screenshots / Recordings

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

Copilot AI review requested due to automatic review settings April 30, 2026 10:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds locale-aware formatting for Pivot Grid date dimension headers by introducing a dimension-level formatter and applying it when extracting row dimension headers.

Changes:

  • Add formatter to IPivotDimension to control display text without affecting grouping keys.
  • Apply dimension formatter when building row header columns.
  • Update date dimension behavior/tests to use locale-aware short date formatting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
projects/igniteui-angular/grids/pivot-grid/src/pivot-row-dimension-content.component.ts Applies the new dimension formatter when extracting header text.
projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.spec.ts Updates expected row header date to a locale-derived short date string.
projects/igniteui-angular/grids/core/src/pivot-grid.interface.ts Introduces IPivotDimension.formatter API with documentation.
projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts Adds locale-aware formatting for full-date leaf values when no custom memberFunction is provided.

Comment thread projects/igniteui-angular/grids/core/src/pivot-grid.interface.ts
const rawHeader = rowData?.dimensionValues.get(field);
let header = rawHeader;
if (dim.formatter != null) {
header = dim.formatter(rawHeader) ?? rawHeader;
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new dimension formatter is invoked with only the raw value, which makes it less capable than other grid formatter patterns (often providing row/column context). Since this is a new API surface, consider extending the signature to accept context (e.g., row group record and/or dimension) and pass it here, so consumers can format based on locale and/or other dimension values without relying on external closures.

Suggested change
header = dim.formatter(rawHeader) ?? rawHeader;
const formatter = dim.formatter as (value: any, dimension?: IPivotDimension, record?: IPivotGridGroupRecord) => any;
header = formatter(rawHeader, dim, rowData) ?? rawHeader;

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +164
formatter: (value: any) => {
const dateValue = (value !== null && value !== undefined && value !== '')
? getDateFormatter().createDateFromValue(value)
: null;
return dateValue
? getDateFormatter().formatDateTime(dateValue, undefined, { dateStyle: 'short' })
: value;
}
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDateFormatter() is called twice per formatted cell. If formatter is invoked frequently (row header rendering/virtualization), this adds avoidable overhead. Capture the formatter instance once in the closure (or outside the callback) and reuse it for both createDateFromValue and formatDateTime.

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +167
if (options.fullDate) {
if (inBaseDimension.memberFunction) {
// User supplied a custom memberFunction — preserve it without adding a formatter.
baseDimension = inBaseDimension;
} else {
// No custom memberFunction: create a new dimension object with a locale-aware
// formatter that shows dates in short-date format.
baseDimension = {
...inBaseDimension,
formatter: (value: any) => {
const dateValue = (value !== null && value !== undefined && value !== '')
? getDateFormatter().createDateFromValue(value)
: null;
return dateValue
? getDateFormatter().formatDateTime(dateValue, undefined, { dateStyle: 'short' })
: value;
}
};
}
}
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New branching behavior is introduced for options.fullDate based on whether inBaseDimension.memberFunction is provided. The updated spec covers locale formatting, but it doesn’t appear to cover the memberFunction branch (ensuring no formatter is attached/used). Add a unit test that sets fullDate: true with a custom memberFunction and asserts header rendering behaves as intended for that path.

Copilot uses AI. Check for mistakes.
Comment on lines +1248 to +1249
const formattedDate = Intl.DateTimeFormat(undefined, { dateStyle: 'short' }).format(new Date(2021, 11, 8));
const expectedHeaders = ['All Periods', '2021', 'Q4', 'December', formattedDate];
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production code formats via getDateFormatter().formatDateTime(..., { dateStyle: 'short' }), while the test computes expectations using Intl.DateTimeFormat(...). These can differ across environments/locales/formatting backends even when both are 'short'. To avoid CI flakiness, compute formattedDate using the same date formatting utility used by the component (or explicitly set/override the test locale to a known value and assert that exact string).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants