Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/vue/src/grid/src/table/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,8 @@ const Methods = {
let { fit, columnStore, columnChart, isGroup } = this
let tableHeight = bodyEl.offsetHeight
let overflowY = bodyEl.scrollHeight > bodyEl.clientHeight
// 解决缩放时会出现滚动条的问题
let bodyW = Math.floor(bodyEl.getBoundingClientRect().width)
// 当浏览器缩放时,实际宽度会出现小数点,clientWidth会取整,此处减去1px解决缩放时会出现滚动条的问题
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The adjustment of bodyW to bodyEl.clientWidth - 1 is a critical fix to handle fractional pixel widths that can cause scrollbars to appear during browser zoom. This change ensures that the grid width calculation is more accurate and prevents unwanted scrollbars.

let bodyW = bodyEl.clientWidth - 1
Comment on lines +1019 to +1020
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid subtracting a hardcoded pixel; use Math.floor on getBoundingClientRect().width
Subtracting 1 px unconditionally can undercut the true available width (even when there’s no fractional pixel) and skew the computed scrollbarWidth by +1, potentially misaligning sticky columns. Instead, floor the fractional width from the bounding rect to handle sub-pixel values without a hardcoded hack.

-    // 当浏览器缩放时,实际宽度会出现小数点,clientWidth会取整,此处减去1px解决缩放时会出现滚动条的问题
-    let bodyW = bodyEl.clientWidth - 1
+    // 使用 getBoundingClientRect 的宽度取整,避免浏览器缩放带来的分数像素导致滚动条
+    const bRectWidth = bodyEl.getBoundingClientRect().width
+    let bodyW = Math.floor(bRectWidth)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 当浏览器缩放时,实际宽度会出现小数点,clientWidth会取整,此处减去1px解决缩放时会出现滚动条的问题
let bodyW = bodyEl.clientWidth - 1
// 使用 getBoundingClientRect 的宽度取整,避免浏览器缩放带来的分数像素导致滚动条
const bRectWidth = bodyEl.getBoundingClientRect().width
let bodyW = Math.floor(bRectWidth)

let { leftList, rightList } = columnStore

// 此处操作很重要,这里会计算所有列的宽度并且计算出表格整体宽度
Expand Down
Loading