Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/VirtualTable/BodyGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
// ========================== Column ==========================
const columnsWidth = React.useMemo<[key: React.Key, width: number, total: number][]>(() => {
let total = 0;
return flattenColumns.map(({ width, key }) => {
total += width as number;
return [key, width as number, total];
return flattenColumns.map(({ width, minWidth, key }) => {
const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The expression (width as number) || 0 is not robust enough to handle all possible string values for width. If width is a string containing units, like '100px', the Number(width) conversion at runtime will result in NaN. Consequently, NaN || 0 evaluates to 0, causing the column's width to be incorrectly set to zero.

To ensure widths are parsed correctly, even when they include units like px, it is better to use parseFloat. This function will extract the numerical value from the string, providing a more reliable width calculation.

      const finalWidth = Math.max(parseFloat(String(width)) || 0, (minWidth as number) || 0);

total += finalWidth;
return [key, finalWidth, total];
});
}, [flattenColumns]);

Expand Down