-
Notifications
You must be signed in to change notification settings - Fork 160
fix(pivot-grid): fix date format based on the localization #17256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 21.2.x
Are you sure you want to change the base?
Changes from 2 commits
f054eb5
e86ce0f
b2b689e
440d496
bf31407
039f036
7595db4
179942e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,33 @@ export class IgxPivotDateDimension implements IPivotDimension { | |
| this.enabled = inBaseDimension.enabled; | ||
| this.displayName = inBaseDimension.displayName || this.resourceStrings.igx_grid_pivot_date_dimension_total; | ||
|
|
||
| const baseDimension = options.fullDate ? inBaseDimension : null; | ||
| // When fullDate is enabled and the user has not provided a custom memberFunction, | ||
| // attach a locale-aware formatter so the leaf date values are displayed in | ||
| // short-date format instead of the raw data string. | ||
| // When the user provides their own memberFunction, the dimension is used as-is | ||
| // (spread-create is skipped) to avoid overriding the user's intended formatting. | ||
| let baseDimension: IPivotDimension = null; | ||
| 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; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
|
Comment on lines
+147
to
+167
|
||
|
|
||
| const monthDimensionDef: IPivotDimension = { | ||
| memberName: 'Months', | ||
| memberFunction: (rec) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1245,7 +1245,8 @@ describe('IgxPivotGrid #pivotGrid', () => { | |
| // check rows | ||
| const rows = pivotGrid.rowList.toArray(); | ||
| expect(rows.length).toBe(5); | ||
| const expectedHeaders = ['All Periods', '2021', 'Q4', 'December', '12/08/2021']; | ||
| const formattedDate = Intl.DateTimeFormat(undefined, { dateStyle: 'short' }).format(new Date(2021, 11, 8)); | ||
| const expectedHeaders = ['All Periods', '2021', 'Q4', 'December', formattedDate]; | ||
|
Comment on lines
+1272
to
+1273
|
||
| const rowHeaders = fixture.debugElement.queryAll( | ||
| By.directive(IgxPivotRowDimensionHeaderComponent)); | ||
| const rowDimensionHeaders = rowHeaders.map(x => x.componentInstance.column.header); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.