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

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit f1cd1ae710)
This commit is contained in:
Michael S. Molina
2026-03-31 08:19:22 -03:00
committed by Michael S. Molina
parent ddb285b4c3
commit ec9ffc4c31
2 changed files with 105 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,9 @@ 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 +1118,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]],