fix(pivot-table): safely cast numeric strings to numbers for date formatting (#38953)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael S. Molina
2026-03-31 08:19:22 -03:00
committed by GitHub
parent e0a0a22542
commit f1cd1ae710
2 changed files with 103 additions and 2 deletions

View File

@@ -269,6 +269,11 @@ function sortHierarchicalObject(
return result;
}
function convertToNumberIfNumeric(value: string): string | number {
const n = Number(value);
return value.trim() !== '' && !Number.isNaN(n) ? n : value;
}
function convertToArray(
obj: Map<string, unknown>,
rowEnabled: boolean | undefined,
@@ -868,7 +873,7 @@ export class TableRenderer extends Component<
);
};
const headerCellFormattedValue =
dateFormatters?.[attrName]?.(colKey[attrIdx]) ?? colKey[attrIdx];
dateFormatters?.[attrName]?.(convertToNumberIfNumeric(colKey[attrIdx])) ?? colKey[attrIdx];
const { backgroundColor, color } = getCellColor(
[attrName],
headerCellFormattedValue,
@@ -1111,7 +1116,7 @@ export class TableRenderer extends Component<
: null;
const headerCellFormattedValue =
dateFormatters?.[rowAttrs[i]]?.(r) ?? r;
dateFormatters?.[rowAttrs[i]]?.(convertToNumberIfNumeric(r)) ?? r;
const { backgroundColor, color } = getCellColor(
[rowAttrs[i]],