Skip to content

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

Open
Hristo313 wants to merge 7 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 7 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
Comment thread projects/igniteui-angular/grids/core/src/pivot-grid-dimensions.ts Outdated
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.

@dkamburov dkamburov self-assigned this May 4, 2026
@dkamburov dkamburov requested a review from skrustev May 4, 2026 07:40
Copy link
Copy Markdown
Member

@skrustev skrustev left a comment

Choose a reason for hiding this comment

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

Please provide more context to the formatter, like dimension and row data.

*/
/* csTreatAsEvent: PivotDimensionFormatterEventHandler */
/* blazorOnlyScript */
formatter?: (value: any) => string | null | undefined;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also naming it just formatter is kinda confusing. This is not a formatter for the dimension cell. I think it should be named something like headerFormatter/columnFormatter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done in bf31407: renamed the new dimension display hook from formatter to headerFormatter to make the scope explicit for dimension headers.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

Please provide more context to the formatter, like dimension and row data.

Implemented in bf31407 (and aligned in 039f036): dimension header formatting now receives additional context (value, dimension, and row data when available). Row headers pass row group data, while column headers pass undefined for row data.

@Hristo313
Copy link
Copy Markdown
Contributor Author

@copilot Fix the failing tests

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@copilot Fix the failing tests

Fixed in 7595db4. The failing CI test was caused by strict object identity checks in the new pivot formatter-context spec; I replaced them with stable structural assertions (jasmine.objectContaining) so the test validates the expected context without reference-equality flakiness.

@Hristo313 Hristo313 requested a review from skrustev May 7, 2026 08:39
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.

5 participants