From 0837832a7bf3447b67e8a2dc6aa07eb4a2db2744 Mon Sep 17 00:00:00 2001 From: gongbei Date: Wed, 8 May 2024 17:31:37 +0800 Subject: [PATCH] feat: Column width supports this type of writing, such as '100' and '100px' --- src/hooks/useColumns/useWidthColumns.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hooks/useColumns/useWidthColumns.tsx b/src/hooks/useColumns/useWidthColumns.tsx index fb5f2d885..b264b328b 100644 --- a/src/hooks/useColumns/useWidthColumns.tsx +++ b/src/hooks/useColumns/useWidthColumns.tsx @@ -9,6 +9,18 @@ function parseColWidth(totalWidth: number, width: string | number = '') { if (width.endsWith('%')) { return (totalWidth * parseFloat(width)) / 100; } + + /** + * Column width supports this type of writing, such as '100' and '100px' + */ + if (isNaN(Number(width))) { + if (width.endsWith('px')) { + return Number(width.replace(/px/, '')); + } + } else { + return Number(width); + } + return null; }